Here is the code, I defined two class named Father and Son, and create them in the main function:
public class Test {
public static void main(String[] ar
Let's start with the constructor of Son
.
public Son() {
super(); // implied
who();
tell(name);
}
Father's constructor is called.
public Father() {
who();
tell(name);
}
Because who()
is overridden by Son
, the Son
's version will be called, printing "this is son".
tell()
is also overridden but the value passed in is Father.name
, printing "this is father".
Finally, the who()
and tell(name)
calls inside Son
's constructor will be made printing "this is son" and "this is son" respectively.