elibraryportal Logo

Super Keyword in Java | Example

super keyword is a reference variable that is used to refer immediate parent class objects.

Usage of Super Keyword

  • Variable.
  • Method.
  • Constructor

1) Super keyword use in Variable

super keyword allow to access the data member, field of parent class. same fields or data member of parent class and child class.

Example:

Output :-

Super keyword use in Variable Example

Note :-To access the parent property, so use super keyword.

2) Super keyword use in Method

→ super keyword can also be used to immediate parent class method. same named methods of parent and child class .

Example:

Output :-

Super keyword use in Method Example

3) Super keyword use in Constructor

→ super keyword can also be used to invoke the parent class constructor

Example:

Output :-

Super keyword use in Constructor Example

Real Example :-

Example:

Output :-

Super keyword use in Constructor Example
Next Topic