What Does super Do in OOP?
Understand the super keyword in OOP — calling parent constructors and extending overridden methods — with clear Java code examples.
Expected Interview Answer
"super" is a keyword used inside a subclass to call a method or constructor defined on its parent class, most commonly to invoke the parent constructor or to extend rather than fully replace an overridden method.
When a subclass overrides a method, calling “super.method()” (Java/C++) or “super().method()” (Python) inside the override runs the parent's original implementation, letting the subclass add behavior before or after it instead of duplicating the parent's logic. In constructors, "super(...)" invokes the parent class constructor to ensure inherited fields are properly initialized before the subclass adds its own; in Java, if you don't call it explicitly, the compiler inserts an implicit no-arg “super()” call as the first statement. This is essential in multi-level inheritance chains, where each level may need to run its ancestor's setup logic in order. Using “super” avoids duplicating parent logic and keeps the initialization or override chain consistent even if the parent class changes later.
- Reuses parent constructor logic instead of duplicating field initialization
- Lets an override extend parent behavior instead of fully replacing it
- Keeps multi-level inheritance chains initialized in the correct order
- Reduces duplication and keeps subclasses resilient to parent-class changes
AI Mentor Explanation
A regional academy trains players using the national board's base curriculum first, then layers on local specialization drills on top of it, rather than writing an entirely separate training manual from scratch. Calling “super” is like the academy explicitly invoking “run the national board's program first,” ensuring the fundamentals are covered before the specialized additions happen. If the national board updates its curriculum, the academy automatically benefits without rewriting its own plan. That is what super() gives a subclass: guaranteed access to the parent's established setup, extended rather than duplicated.
Step-by-Step Explanation
Step 1
Identify the parent behavior to reuse
Determine whether you need the parent constructor or a parent method's original logic.
Step 2
Call super in the constructor
Invoke “super(...)” as (implicitly or explicitly) the first statement so inherited fields are initialized.
Step 3
Call super inside an override
Use “super.method()” within the overriding method to run the parent's version at the point you choose.
Step 4
Add subclass-specific logic
Extend the result with new behavior before or after the super call, rather than duplicating parent code.
What Interviewer Expects
- Correct explanation of super in both constructor and method-override contexts
- Awareness that Java inserts an implicit no-arg super() if omitted
- Understanding that super lets an override extend rather than fully replace behavior
- A code example showing super() used in a constructor chain
Common Mistakes
- Thinking super() must always be called with no arguments
- Forgetting that in Java, super() must be the first statement in a constructor
- Believing super and this can both be called as the first statement in the same constructor
- Confusing super (parent access) with self/this (own instance access)
Best Answer (HR Friendly)
“super is how a subclass reaches back to its parent class — usually to run the parent's constructor so inherited fields get set up properly, or to call the parent's version of a method you've overridden so you can add to it instead of rewriting it entirely. It keeps subclasses from duplicating logic that already exists in the parent.”
Code Example
class Vehicle {
protected String type;
Vehicle(String type) { this.type = type; }
void describe() { System.out.println("A " + type + " vehicle"); }
}
class ElectricCar extends Vehicle {
int batteryKwh;
ElectricCar(int batteryKwh) {
super("electric car"); // runs parent constructor first
this.batteryKwh = batteryKwh;
}
@Override
void describe() {
super.describe(); // reuse parent’s implementation
System.out.println("with a " + batteryKwh + " kWh battery");
}
}Follow-up Questions
- What happens if you don't call super() explicitly in a Java constructor?
- Can you call super() after other statements in a constructor?
- How does super work differently in Python's multiple inheritance (MRO)?
- Can you call a grandparent class's method using super in a multi-level hierarchy?
MCQ Practice
1. In Java, what happens if a subclass constructor omits an explicit super() call?
Java automatically inserts an implicit super() as the first statement if none is written, provided the parent has a no-arg constructor.
2. What does calling super.method() inside an override typically achieve?
super.method() invokes the parent class's version of the overridden method, allowing the subclass to build on it.
3. In a Java constructor, where must an explicit super(...) call appear?
Java requires an explicit super(...) call to be the very first statement in a subclass constructor.
Flash Cards
super in one line? — A keyword used by a subclass to call its parent class's constructor or method.
Where must super() go in a Java constructor? — As the first statement, explicit or implicit.
Why call super inside an override? — To reuse and extend the parent's behavior instead of duplicating it.
What if super() is omitted in Java? — The compiler inserts an implicit no-arg super() call automatically.