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

Why is it dangerous to call an overridable method from a constructor?

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

Because the subclass constructor body has not run yet when the superclass constructor executes, so an overridden method invoked from the superclass constructor sees the subclass's fields still at their defaults (null/0).

Explanation

This leads to subtle NPEs or half-initialized state. The safe options are to make such methods final or private, or to use a factory/builder so the object is fully constructed before any behavior runs.

Common mistakes
  • Calling an overridable method from a constructor and reading subclass fields that are still null.
  • Not making such helper methods private or final.

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