Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › OOP I — Classes, Objects, Constructors

Walk through the exact order of initialization when 'new SubClass()' runs, including static and instance initializers.

Level III · MidOOP I — Classes, Objects, Constructors
Short answer

On first use the class is loaded and its static fields and static initializer blocks run once, parent before child.

Explanation

Then for each instantiation: the constructor implicitly calls super() first, then the instance field initializers and instance initializer blocks run top-to-bottom, then the rest of the constructor body. So a parent constructor can observe a child field that has not yet been initialized — a real trap when a parent constructor calls an overridden method.

Common mistakes
  • Forgetting static initializers run once, at class initialization, before any instance work.
  • Saying the subclass constructor body runs before the superclass constructor.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for OOP I — Classes, Objects, Constructors.

Practise free

More on OOP I — Classes, Objects, Constructors