Java Program for Hierarchical inheritance

  Hierarchical Inheritance Program in Java

class A  //Base class
{
void show()
{
System.out.println("Base class A");
}
}

class B extends A // derived class inherits base class
{
void show1()
{
System.out.println("Derived class of A = B");
}
}

class C extends A //Derived class inherits base class
{
void show2()
{
System.out.println("Derived class of A = C");
}
}

class D extends B // Derived class of B
{
void show3()
{
System.out.println("Derived class of B = D");
}
}

class HierarchicalDemo
{
public static void main(String args[])
{
A a = new A();
B b = new B();
C c = new C();
D d = new D(); 
 
    a.show();
b.show();
b.show1();
c.show();
c.show2();
d.show();
d.show1();
d.show3();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *