Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Constructor chains and trace traps

โญ beginnerโณ 10 min read๐Ÿ“ Lesson 51 of 256

Build order AB, what isn't inherited, calling overridden methods from constructors.

Tracing a constructor chain โ€” the exam's favorite:

public class A {
    public A() { System.out.print("A"); }
}

public class B extends A {
    public B() { System.out.print("B"); }   // implicit super() first
}

new B() prints AB: the superclass part is always built first. With explicit super(args) and fields, the order is: super constructor โ†’ subclass field initializers โ†’ subclass constructor body.

What subclasses don't inherit: private fields (exist but hidden), constructors (called, not inherited), static methods are hidden not overridden (out of scope here).

Common trace traps: calling an overridden method from inside the superclass constructor runs the subclass version before subclass fields are initialized โ€” a classic "why is my field null" puzzle. The exam uses this only in the hardest trace items; know the mechanism, don't memorize beyond it.

โšก Now practice

Ready to Code
Inheritance repsChaining, overriding, dispatch, super.method, chain debugging.
5 challenges ยท ยท ~55 min