Quick revision
The short answer
The superclass constructor runs before any of the subclass's own fields are assigned, but a call to an overridable method inside it is already dispatched to the subclass override. So the override runs on a half-built object and sees default values: null, 0 and false, even for final fields. The fix is to stop calling overridable methods from constructors, or, on Java 25, to assign the subclass fields before calling super(...).
What to remember
In this answer, we saw that Java runs the superclass constructor before the subclass assigns any of its own fields, while dynamic dispatch already sends calls to the subclass override. The override therefore reads default values, even for final fields. We fixed it by keeping constructor calls to private or final methods, by moving the hook into a factory that runs after construction, or on Java 25 by assigning subclass fields before super(...), and we saw that PMD, SpotBugs, Sonar and javac's this-escape lint can catch the pattern early.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The superclass constructor runs before any of the subclass's own fields are assigned, but a call to an overridable method inside it is already dispatched to the subclass override. So the override runs on a half-built object and sees default values: null, 0 and false, even for final fields. The fix is to stop calling overridable methods from constructors, or, on Java 25, to assign the subclass fields before calling super(...).
Why this question is asked
This bug looks impossible the first time we meet it: the field is set in the constructor, it is even final, and still the method reads null. It shows up in real code when a framework base class calls a template method such as init() or configure() from its constructor, and a subclass relies on its own fields there. Interviewers ask it because the answer shows whether we really know the order in which Java builds an object. In this answer, we will recap that order, reproduce the problem, follow the construction step by step, and then go through the fixes, including the new option that Java 25 gives us and the tools that catch the problem before it ships.
1A Quick Recap of How an Object Is Built
When we write new Child("report"), the JVM first allocates memory for the whole object, with room for the fields of Child and of every superclass. All of those fields start with their default values: null for references, 0 for numbers and false for booleans.
Then the constructors run, from the top of the hierarchy down. The Child constructor starts by calling super(...), either explicitly or implicitly. Only after the superclass constructor has returned does Child run its own field initializers (the = something parts of field declarations) and then the rest of its constructor body. So while Base's constructor is running, every field declared in Child still holds its default value.
The second ingredient is dynamic dispatch, the rule that a call to an instance method goes to the version in the object's actual class, not the class where the call is written. The object being built is already a Child, so a call to describe() inside Base's constructor goes to Child.describe().
2Reproducing the Problem
Here is a small version of the bug. Base calls describe() from its constructor, and Child overrides it to print two of its own fields.
Notice that both fields are wrong, not just one. name is assigned in the constructor body and size by a field initializer, and both of those run only after super() returns. The final keyword does not help either. final means the field is assigned exactly once, but it does not stop anyone from reading it before that one assignment happens.
3Following the Construction Step by Step
It helps to put the steps in the order the JVM actually executes them. The important moment is the third step: Base's constructor is running, but the call it makes lands in Child.
- Allocate the objectall fields are null, 0 or false
- Child(...) calls super()Child's own code has not run yet
- Base() calls describe()dynamic dispatch picks
Child.describe() - Child.describe() reads name and sizeprints null 0
- Base() returnsback in the Child constructor
- Child field initializers runsize = 10
- Rest of the Child constructor runs
this.name= "report"
7 steps in order. Play them, or step through them one at a time.
So the override is not wrong, and the superclass is not wrong in isolation. The trouble is the combination: the superclass hands control to subclass code before the subclass has had any chance to set itself up.
There is one case that seems to work and confuses people. If we write private final String name = "child"; with a literal, the field is a constant variable, and the compiler copies the value "child" straight into describe(). The method then prints child even during the superclass constructor. Change the initializer to a method call or a constructor parameter, and null comes back. We should never rely on that difference.
4Fix 1: Do Not Call Overridable Methods From Constructors
The simplest and most common fix is a rule: a constructor may only call methods that cannot be overridden. If describe() is private, final or static, the call in Base always runs Base's code, and no subclass can be surprised.
If the superclass really needs a step that subclasses customize, it should not run that step from its constructor. It can run it later, the first time the object is used, or let a factory run it once construction is complete.
5Fix 2: Construct First, Then Initialize From a Factory
A static factory method gives us a clean two-phase start. The constructor only stores fields. The factory then calls the hook on a fully built object.
Making the constructor private forces every caller through create(), so nobody can forget the second phase. Spring follows the same idea: it calls @PostConstruct methods and InitializingBean.afterPropertiesSet() only after the bean is constructed and its dependencies are injected.
6Fix 3: Assign the Fields Before super(...) on Java 25
Java 25 made flexible constructor bodies final (JEP 513). A constructor may now run statements before its call to super(...), and among other things it may assign fields of its own class there, as long as the field is declared without an initializer. If Child assigns its fields first, the override sees real values even when Base calls it.
This fixes the symptom precisely, and it is a good option when we cannot change the superclass, for example when it lives in a library. But the design is still fragile: the next subclass author must remember to do the same. Where we own the superclass, fixes 1 and 2 remove the trap for everyone.
7Catching It Before It Ships
We do not have to find these bugs by debugging. Static analysis tools flag them. PMD has a rule for constructors that call overridable methods, SpotBugs reports an overridable method call in a constructor, and SonarQube has an equivalent rule. Since JDK 21, javac itself can warn with -Xlint:this-escape when a constructor lets this escape to code that a subclass could override. Turning one of these on in the build, and failing the build on it for new code, is cheaper than any review checklist.
8Follow-up questions
Does the same problem happen with a call from an instance initializer block?
Yes. Instance initializer blocks and field initializers of the superclass run as part of the superclass constructor, so a call from them to an overridable method also reaches the subclass before the subclass fields are set. The rule is about any code that runs during superclass construction, not only the constructor body.
Why does Java allow this at all? C++ does not dispatch to the subclass during construction.
Java decided that an object has its final class from the moment it is allocated, so dispatch always uses that class. C++ treats the object as an instance of the class whose constructor is running. Java's choice is simpler for the JVM but leaves the danger to us, which is why the guidance and the lint warnings exist.
Is it safe to call an abstract method from the constructor of an abstract class?
It is exactly the same situation, because the only implementation that can run is a subclass override, and it will run before the subclass fields are set. Template methods that subclasses implement should be called after construction, for example from a public start() or from a factory.
9Conclusion
In this answer, we saw that Java runs the superclass constructor before the subclass assigns any of its own fields, while dynamic dispatch already sends calls to the subclass override. The override therefore reads default values, even for final fields. We fixed it by keeping constructor calls to private or final methods, by moving the hook into a factory that runs after construction, or on Java 25 by assigning subclass fields before super(...), and we saw that PMD, SpotBugs, Sonar and javac's this-escape lint can catch the pattern early.
Open with
What is happening is a construction-order problem. When I create the subclass, the JVM allocates the object with all fields at their defaults, and the subclass constructor calls super first.
Then, if they want more
The superclass constructor then calls the overridable method, and because the object is already a Child, dynamic dispatch runs the subclass override. At that point the subclass field initializers and constructor body have not run, so the override sees null, zero or false, and final does not help, because final only means assigned once, not assigned before it is read.
The one exception is a final field initialized with a compile-time constant, which the compiler inlines, and that is why the bug sometimes seems to come and go. My first fix is the rule that constructors call only private, final or static methods.
If the superclass needs a customizable step, I move it out of the constructor into a factory or an explicit init phase that runs after construction, the way Spring runs PostConstruct.
If I cannot change the superclass and I am on Java 25, flexible constructor bodies let the subclass assign its fields before calling super, which makes the override see real values. And I would turn on a check for it, such as PMD's rule, SpotBugs or javac's this-escape lint, so it does not come back.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A subclass overrides a method that the superclass constructor calls. The override reads...": https://scrivio-interview-library.netlify.app/java/classes-and-objects/8918712e98/