Thursday 17 March 2016

How to create hierarical level inheritance in java

3.Hierarchical level Inheritance:-
 When more than two classes using only one class properties is called hierarchical level.


class GrandFather

{

public void property1()

{

System.out.println("Full property of Grandfather");

}
}
class Father extends GrandFather
{
public void property2()
{
System.out.println("Property of house");
}
}
class Son extends GrandFather
{
public void property3()
{
System.out.println("Property of car");
}
}
class Main
{
public static void main(String args[])
{
Father f=new Father();
f.property2();
f.property1();

Son s=new Son();
s.property3();
s.property1();
}
}

OUTPUT:-
C:\Users\Satyendra\Desktop>javac Main.java
C:\Users\Satyendra\Desktop>java Main
Property of house
Full property of Grandfather
Property of car
Full property of Grandfather

No comments:

Post a Comment