Programs of hierarchical inheritance

Program
class A
{
public void method1()
{
System.out.println(“method of Class A”);
}
}
class B extends A
{
public void method2()
{
System.out.println(“method of Class B”);
}
}
class C extends A
{
public void method3()
{
System.out.println(“method of Class C”);
}
}
class D extends A
{
public void method4()
{
System.out.println(“method of Class D”);
}
}
class test
{
public void methodB()
{
System.out.println(“method of Class B”);
}
public static void main(String args[])
{
B obj1 = new B();
C obj2 = new C();
D obj3 = new D();
obj1.method1();
obj2.method1();
obj3.method1();
}
}

Output:
method of Class A
method of Class A
method of Class A

 

Leave a Reply

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