Understanding initialization order across class loading, inheritance, and instance instantiation.
super() call).
class Parent {
static { System.out.println("1. Parent Static Block"); }
{ System.out.println("3. Parent Instance Block"); }
Parent() {
System.out.println("4. Parent Constructor");
}
}
class Child extends Parent {
static { System.out.println("2. Child Static Block"); }
{ System.out.println("5. Child Instance Block"); }
Child() {
// implicit super();
System.out.println("6. Child Constructor");
}
}
Click Step Execution to simulate running new Child().
super() to fully construct the parent object first. Static elements only run once when the class is loaded into the JVM.