Friday , January 20 2017
Home / JAVA / Java program to use super keyword

Java program to use super keyword

Super is a keyword which refers to reference of base class. Super is used to call any constructor or any method of base class but it must be 1st line of the derived class constructor.

We use the super keyword in java for two purposes:

1-      Super keyword for calling base class constructor.
2-      Super keyword for calling base class function.

Calling Constructor

In this we have two class parent class and child class and define the constructor for each class. Now if we want to call the constructor of base class than we use super keyword for calling the base class constructor. Also super keyword must be use inside another child class constructor and must be the first line in the child class constructor.

Example #1: 

Example #2: 

Method Overriding

The method of calling base class constructor and base class method are same as by using the super keyword which must be the 1st line of the method in the child class. Its technique of using super keyword is same as in the constructor. Here we show the program of calling base class method with same name but different functionality. But if we have to call the base class method as it is than we call it through the super keyword.



Also See:   Program to check Upper Triangular matrix

Check Also

Program for Matrix Multiplication in JAVA

Matrix Multiplication:– Here is given a Java Program for Matrix Multiplication also call matrix product. In ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.