Super Keyword

Posted By on September 16, 2014


Download PDF
This Keyword in JAVA
Characteristics of Object Oriented Programming Language

super keyword

The super is a reference variable that is used to refer immediate parent class object.

Whenever you create the instance of subclass, an instance of parent class is created implicitly i.e. referred by super reference variable.

Usage of super Keyword

  1. super is used to refer immediate parent class instance variable.
  2. super() is used to invoke immediate parent class constructor.
  3. super is used to invoke immediate parent class method.

 

//example of super keyword 
  1. class Vehicle{  
  2.   int speed=50;  
  3. }  
  4.   
  5. class Bike4 extends Vehicle{  
  6.   int speed=100;  
  7.       
  8.   void display(){  
  9.    System.out.println(super.speed);//will print speed of Vehicle now  
  10.   }  
  11.   public static void main(String args[]){  
  12.    Bike4 b=new Bike4();  
  13.    b.display();  
  14.      
  15. }  
  16. }  
Output:50
This Keyword in JAVA
Characteristics of Object Oriented Programming Language

Download PDF

Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby

Website: http://world4engineers.com