Basic example of Hierarchical Inheritance in Java


Here is the simple program for printing basic example of Hierarchical Inheritance in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class class_A
{
  public void adisplay()
  {
    System.out.print("\nI am Class A");
  }
}
class class_B extends class_A
{
  public void bdisplay()
  {
    System.out.print("\nI am Class B");
  }
}
class class_C extends class_A
{
  public void cdisplay()
  {
    System.out.print("\nI am Class C");
  }
}
class class_D extends class_A
{
  public void ddisplay()
  {
    System.out.print("\nI am Class D");
  }
}
class class_main
{
  public static void main(String args[])
  {
    class_B o1 =new class_B();
    o1.adisplay();
    o1.bdisplay();
    class_C o2 =new class_C();
    o2.adisplay();
    o2.cdisplay();
    class_D o3 =new class_D();
    o3.adisplay();
    o3.ddisplay();
  }
}
To download raw file Click Here

Output

I am Class A
I am Class B
I am Class A
I am Class C
I am Class A
I am Class D


Learn All in Tamil © Designed & Developed By Tutor Joes