Monday, December 5, 2016

Write a JAVA program to give the example for ‘super’ keyword.

Aim: Write a JAVA program to give the example for ‘super’ keyword.

Program:


class Vehicle
{  
  int speed=50; 
  Vehicle()
  {
    System.out.println("Vehicle is created");
  }  
}  
  
class Bike extends Vehicle
  int speed=100;  
  void display()
  {  
   System.out.println(super.speed);//will print speed of Vehicle now  
  }   
  Bike()
  {  
   super();//will invoke parent class constructor  
   System.out.println("Bike is created");  
  }  
  public static void main(String args[])
  {  
   Bike b=new Bike();  
   b.display();     
  }  
}  

Output:


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home