Unit 3 Cycle 2 Day 2: Error: Missing super() Call
Share
Error: Missing super() Call
Section 3.14 — The super Keyword
Key Concept
When a subclass constructor does not explicitly call super(), Java inserts super() (the no-arg version) automatically. If the superclass does not have a no-argument constructor (because it defined only parameterized constructors), this implicit call fails and the code does not compile. This is one of the most common inheritance compilation errors. The fix is to either add a no-argument constructor to the superclass or have the subclass explicitly call a valid superclass constructor with super(args).
Consider the following classes.
What happens when this code is compiled?
Answer: (B) Compile error: Circle constructor must call super().
Shape has no no-arg constructor (only a one-arg constructor). Circle's constructor does not call super(), so Java tries to insert super() (no args) automatically. This fails because Shape requires a String argument.
Why Not the Others?
(A) The compiler cannot find a matching no-arg constructor in Shape.
(C) This is caught at compile time, not runtime.
(D) private fields are correct for encapsulation. This is not the issue.
Common Mistake
If you do not write super(...) as the first line of a subclass constructor, Java automatically inserts super() (no args). If the parent has no no-arg constructor, this causes a compile error.
AP Exam Tip
Always check: does the parent class have a no-arg constructor? If not, the subclass MUST explicitly call super(args).