Core Java: Calling an overridable method from a constructor can see an uninitialized field

When a superclass constructor calls a method the subclass overrides, that override runs before the subclass's own field initializers, so it observes the field's default value, not the value assigned in the subclass.

Code
class Base {
    Base() {
        System.out.println("Base ctor calls describe(): " + describe());
    }
    String describe() { return "base"; }
}
class Derived extends Base {
    String label = "ready";
    @Override
    String describe() { return "derived label=" + label; }
}
new Derived();
Output
Base ctor calls describe(): derived label=null
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms