Saturday, 16 May 2015

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();
  }
}

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel