Hi all
What i understand from inheritance is that the base class is first initialise b4 the sub.
Why is it that the following code is accessing the overriden method from sub instead of base when calling from base constructor.
To me the subclass is not initialise yet,but still it access that method.
I need some clarity.
Thanks for your help.
class Base
{
void B(){System.out.println("B() method in Base ");}
void A(){System.out.println("A() method in Base ");
B();}
Base(){System.out.println("Base constructor");
A();
}
}
public class Sub extends Base
{
void A(){System.out.println("A() method in Sub ");
B(); }
void B(){System.out.println("B() method in Sub ");}
public static void main(
String args[])
{
new Sub();
}
}