It is just concept of grand parent class child class inheritance of parent class and parent-class is inheritance of grand-parent-class so in this case grand parent-class is implicitly inheriting the properties and the method of grand-parent along with parent-class that's is called multi level inheritance.
Example:-
class A
{
System.out.println("Grand-parent-class");
}
class B extends A
{
System.out.println("Parent-class inheritance of grand-parent");
}
class C extends B
{
System.out.println("child-class inheritance of parent-class");
}
Another example
package com;
/**
*
* @author pradeep
*/
class bike{
public bike()
{
System.out.println("Class bike");
}
public void vehicleType()
{
System.out.println("Vehicle Type: bike");
}
}
class hero extends bike{
public hero()
{
System.out.println("Class hero");
}
public void brand()
{
System.out.println("Brand: hero");
}
public void speed()
{
System.out.println("Max: 70Kmph");
}
}
public class honda extends hero{
public honda()
{
System.out.println("honda : 80kmph");
}
public void speed()
{
System.out.println("Max: 120Kmph");
}
public static void main(String args[])
{
honda obj=new honda();
obj.vehicleType();
obj.brand();
obj.speed();
}
}
Result: output of this program:
run:
Class bike
Class hero
honda : 80kmph
Vehicle Type: bike
Brand: hero
Max: 120Kmph
BUILD SUCCESSFUL (total time: 1 second)
No comments:
Post a Comment