Code:
Parent Class:
public class Parent {
int i = 10;
{
System.out.println(i);
}
public Parent(){
System.out.println("Parent");
}
}
Child Class:
public class Child extends Parent {
int j = 20;
{
System.out.println(j);
}
public Child() {
super();
}
}
Test Class:
public class ConstructorTest {
public static void main(String... args){
Child c = new Child();
}
}
Execution Flow(What I know):
- Identification of instance members from top to bottom in
Parent
Class. - Identification of instance members from top to bottom in
Child
Class. - Execution of instance variable assignments and instance blocks from top to bottom in
Parent
Class. - Execution of
Parent
constructor. - Execution of instance variable assignments and instance blocks from top to bottom in
Child
class. - Execution of
Child
constructor.
Output:
10
Parent
20
My question is: in step 6- During execution of Child
constructor, why the parent constructor is not called again using super()
of child?
so why the output is not:
10
Parent
20
Parent