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: Java Programming Lab
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home