What is the purpose of the super keyword in Java?
The super keyword in Java is a reference to the parent (superclass) of the current class. It has three primary uses: calling a parent class constructor, calling an overridden parent class method, and accessing a parent class field hidden by a subclass field of the same name.
Calling a parent constructor: super() or super(args) must be the first statement in a subclass constructor. If omitted, the compiler inserts an implicit super() call that invokes the parent's no-arg constructor. If the parent class does not have a no-arg constructor (because it defines only parameterized constructors), the subclass must explicitly call super(args) — otherwise the code will not compile.
Calling an overridden parent method: when a subclass overrides a method, the parent's version is still accessible as super.methodName(). This is useful when you want to extend, not replace, the parent's behavior. For example, a subclass's toString() might return super.toString() + ", additionalField=" + field, building on the parent's representation.
Accessing hidden fields: if a subclass declares a field with the same name as a parent field, the parent's field is shadowed. super.fieldName accesses the parent's field. This pattern is rare and generally a code smell — shadowing fields leads to confusing behavior.
super cannot be chained (super.super.method() is not valid in Java). This is deliberate: deep chains would couple subclasses to grandparent implementation details, which is considered harmful to encapsulation.
A key distinction: super() is for constructor chaining up the hierarchy; this() is for constructor chaining within the same class. They cannot both be the first statement, so you must choose one or the other in a given constructor.
Covers the constructor call use (super() as first statement) and the overridden method call use (super.method()), with correct syntax.
Adds the implicit super() insertion rule, the field hiding use case (plus the code smell note), the super.super limitation and rationale, and the contrast with this() constructor chaining.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment