class Super {
Super(){
System.out.println("In Super constructor");
test();
}
void test() {
System.out.println("In Super.test()");
}
}
class Sub extends Super {
Sub() {
System.out.println("In Sub constructor");
}
void test() { // overrides test() in Super
System.out.println("In Sub.test()");
}
}
Output - In Super Constructor
In Sub.test()
In Sub Constructor
Suppose i create a subclass object, so at first superclass's constructor will be called, but then how can it call subclass's test, since the object for the derived class and method's implementation has not been allocated memory?