Unit 3 Cycle 1 Day 21: Inheritance: Constructor Chaining
Share
Inheritance: Constructor Chaining
Section 3.14 — The super Keyword
Key Concept
Constructor chaining in an inheritance hierarchy means each constructor calls its parent's constructor. When you create a subclass object, Java executes constructors from the top of the hierarchy down: Object constructor first, then each intermediate superclass, then the subclass constructor. Each super() call must be the first statement. The AP exam traces multi-level constructor chains where each level passes different arguments to super() and initializes its own fields.
Consider the following classes.
What is printed when new C() is executed?
Answer: (B) A B C
Constructors chain upward. C() implicitly calls super() which is B(). B() implicitly calls super() which is A(). A prints "A ", then B prints "B ", then C prints "C ". Order: A B C.
Why Not the Others?
(A) Parent constructors execute first. C is last, not only.
(C) Constructors execute top-down (parent first), not bottom-up.
(D) B's constructor also executes between A and C.
Common Mistake
Constructor chaining always starts from the top of the hierarchy and works down. When you call new C(), it goes: A constructor, then B constructor, then C constructor.
AP Exam Tip
Every constructor implicitly calls super() as its first line if you do not write it explicitly. This ensures parent initialization happens before child initialization.