Unit 3 Cycle 1 Day 20: Inheritance: Calling super Methods
Share
Inheritance: Calling super Methods
Section 3.14 — The super Keyword
Key Concept
A subclass can call a superclass method using super.methodName(), which is especially useful when overriding a method but wanting to extend rather than replace the superclass behavior. For example, an overridden toString() might return super.toString() + " extra info". Without super., calling toString() from within the override would recursively call itself. The AP exam tests whether super correctly invokes the parent's version versus triggering infinite recursion.
Consider the following classes.
What does new Manager("Jo", 50000, 10000).pay() return?
Answer: (B) 60000.0
Manager's pay() calls super.pay() which returns salary (50000), then adds bonus (10000). Total: 60000.
Why Not the Others?
(A) 50000 is just the salary without the bonus.
(C) 10000 is just the bonus without the salary.
(D) super.pay() correctly calls Employee's pay() method.
Common Mistake
super.method() calls the parent class version. This lets a subclass extend behavior rather than completely replace it. The Manager adds bonus on top of the base salary.
AP Exam Tip
Using super.method() in an overriding method lets you reuse parent logic and add to it. This is a common AP exam pattern.