Constructor Chaining with super() in Java
Fast recall
Quick revision
Core answer
super(args) — the first statement. If you don't write it, the compiler inserts an implicit super() (the parent's no-arg constructor). This guarantees the parent part of the object is fully initialized before the subclass adds its own state.Whether you know super() runs first, the implicit super() insertion, and the failure when the parent has no no-arg constructor.
Not realizing an implicit super() is inserted, leading to a confusing compile error when the parent only has a parameterized constructor.
Explain why parent-first ordering exists (subclass code may rely on inherited state) and how to fix the 'no default constructor in superclass' error.
Interview-ready guide
Interview answer
The key idea here is ordering: when you construct a subclass object, the parent's constructor always runs before the subclass's own body. The mechanism is super(args) — it calls the matching parent constructor and must be the very first statement in your constructor. If you don't write it, the compiler silently inserts a no-argument super() for you, which carries on up the chain all the way to Object.
Parent-first matters because the subclass leans on inherited state — Dog uses the name field that Animal sets up, so if Animal hadn't run, name would still be null when Dog touches it.
Where freshers get tripped up is when the parent defines only a parameterized constructor and no no-arg one. The compiler still inserts its invisible super(), finds nothing to call, and throws a 'no default constructor available' error that points at the subclass — even though you never wrote a super() call. The fix is just an explicit super(name) as the first line. So my rule is simple: if the parent has no no-arg constructor, always call `super` explicitly.
Constructor Chaining with super() in Java
Direct Answer
When you create a subclass object, the subclass constructor must run the parent's constructor first via super(args) — the first statement. If you don't write it, the compiler inserts an implicit super() (the parent's no-arg constructor). This guarantees the parent part of the object is fully initialized before the subclass adds its own state.
Common Mistakes & Pitfalls
- Not knowing the compiler inserts an implicit
super()— when the parent has only a parameterized constructor, that hidden call has nothing to target and you get a 'no default constructor' error you never wrote. - Putting code before
super(args)— it has to be the absolute first statement in the constructor; anything before it is a compile error. - Assuming the chain stops at the immediate parent — it actually runs all the way up to
Object, with each level initialising before the one below it. - Forgetting why order matters — if the parent ran after the child, inherited fields like
namewould still benullwhen the subclass tries to use them.
Check your understanding
Answer these without looking back at the article.
- What compile error do you get when you forget to call super() for a parent with only parameterized constructors?
- Can super() be called from a method (not a constructor)?
- How many levels deep does the constructor chain go in Java?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.