In what order do static blocks, instance initialisers, field initialisers and constructors run when you create a subclass object?
Show the explanation
For new Child() the first time the classes are used:
- Static initialisers and static fields of the parent, then of the child (once per class, when it is loaded).
- For the new object: the child constructor first calls
super(...)— so the parent's instance field initialisers and instance blocks run, then the parent constructor body. - Then the child's instance field initialisers and instance blocks run (in source order), then the child constructor body.
class Parent {
static { System.out.println("1 parent static"); }
{ 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"); }
{ System.out.println("5 child instance block"); }
Child() { super(); System.out.println("6 child constructor"); }
}
// new Child(); prints 1..6 in order; a second new Child() prints only 3..6A practical consequence: never call overridable methods from a constructor. The parent constructor would run the child's override before the child's fields are initialised.
Original UniCircle question. Last reviewed 22 Oct 2026.
