Search⌘ K

Super Keyword

Explore how the super keyword in Java enables access to superclass fields, methods, and constructors from subclasses. Understand its use in inheritance to write clear and modular code by handling field name conflicts, method overriding, and constructor chaining effectively.

What is the super keyword?

this keyword in Java is used to refer to the instance of the current class.

In a similar fashion, the super keyword in Java is used to refer to the SuperClass members from inside the immediate Subclass. The use of super comes into play when we implement inheritance.

Use cases of the super keyword

The super keyword is used in three major contexts:

Accessing parent class fields

Consider the fields named as fuelCap defined inside a Vehicle class to keep track of the fuel capacity of a vehicle. ...