How do you call a parent class's overridden method from a subclass, and what does super refer to?
answer
- super.method() = parent's implementation
- super = same object, parent's view
- no super.super
- super.field reads a shadowed parent field
- forgetting super. → infinite recursion
basics
~10 sUse super.methodName() to call the parent's version of a method that the subclass has overridden. super refers to the parent-class part of the current object.
solid answer
~40 sWhen a subclass overrides a method, calling the method name directly runs the subclass version. To reach the parent's implementation you prefix the call with super, e.g. super.toString(). super is not a separate object — it is a reference to the same instance viewed as its superclass, letting you invoke the inherited (non-overridden) behavior. A common pattern is overriding a method, doing extra work, and delegating the core to super: 'public String toString() { return super.toString() + extra; }'. You can only reach one level up — super always means the immediate parent, and there is no 'super.super'. super.field similarly accesses a parent field that a subclass field shadows. Note super for method calls is unrelated to the super() constructor call, though both use the keyword.
code
java · 13 linesclass Account {
String summary() { return "balance only"; }
}
class SavingsAccount extends Account {
@Override
String summary() {
// delegate to parent, then extend
return super.summary() + " + interest";
}
}
new SavingsAccount().summary(); // "balance only + interest"go deeper
Knows super.method() invokes the parent's version and avoids infinite recursion in an override.
Explains super refers to the same object viewed as the parent, knows super.field for shadowing, and that there is no super.super.
Articulates the delegate-and-extend pattern, why grandparent access is forbidden (invariant protection), and field hiding vs method overriding.
Reasons about when super-call chains create fragile base classes and designs template-method or hook patterns to make extension points explicit and safe.
## The problem super solves When a subclass **overrides** a method, it provides its own body for a method signature that already exists in the parent. **Overriding** means redefining an inherited instance method with the same name and parameters so the subclass version is used instead. Once you override, simply writing the method name from inside the subclass runs *your* version — there is no longer a direct way to name the parent's hidden implementation. That is exactly what `super` restores. ## What super is `super` is a keyword that, inside an instance method or constructor, refers to **the current object viewed as an instance of its immediate superclass**. It is the *same* object in memory — there is no second object. It just tells the compiler: "resolve this member starting at the parent level, skipping any override in this subclass." ```java class Animal { String describe() { return "an animal"; } } class Dog extends Animal { @Override String describe() { return super.describe() + " that barks"; // calls Animal.describe() } } // new Dog().describe() -> "an animal that barks" ``` Without `super.`, the call inside `Dog.describe()` would recurse into `Dog.describe()` forever (a `StackOverflowError`). ## The delegate-and-extend pattern The most common use is *augmenting* inherited behavior: do the parent's work, then add to it (or before it). This keeps the parent's logic authoritative and avoids copy-pasting: ```java @Override public String toString() { return super.toString() + " [extra=" + extra + "]"; } ``` ## super.field — shadowing If a subclass declares a field with the **same name** as a parent field, the subclass field **shadows** (hides) the parent one. (Note: hidden, not overridden — fields are not polymorphic.) `super.name` reads the parent's field, `this.name` the subclass's. Field shadowing is usually a design smell, but `super.field` is how you disambiguate if it happens. ## Only one level up `super` always refers to the **immediate** parent. There is **no** `super.super.method()` — Java deliberately forbids reaching past your direct parent, because skipping a level would let a class bypass an intermediate class's intentional override and break its invariants. ## Two unrelated uses of the keyword The keyword `super` appears in two contexts: (1) `super.member` — accessing a parent member (this question), and (2) `super(...)` — invoking a parent **constructor** as the first statement of a subclass constructor. They share a keyword but solve different problems; don't conflate them. ## Static methods `super` works for instance members. Static methods are not overridden (they are *hidden*), and you reach a parent static method by class name (`Animal.foo()`), not `super`.
- What happens if you call the overridden method without super inside the override?It recurses into the same subclass method again, causing infinite recursion and a StackOverflowError.
- Can you write super.super.method() to reach a grandparent?No. Java only allows super to reference the immediate parent; reaching past it is forbidden by design.
super.x() is like asking 'how did my parent do this?' before adding your own twist — you are still the same person, just consulting the inherited playbook.
saying these in an interview costs you the question
- Thinking super is a separate parent object rather than the same instance
- Believing super.super is allowed
- Using super to call a static parent method (use the class name instead)
- Confusing super.method() with the super() constructor call