WAP to create three class hierarchy as A->B->C, Each class declares a method named hello () with same type signature. Create object of class A using constructor of class C with use of that object call hello() to check which method is called
class A
{
void hello()
{
System.out.println("This is class A");
}
}
class B extends A
{
B()
{
super.hello();
}
void hello()
{
System.out.println("The class B are calling");
}
}
class C extends B
{
C()
{
super.hello();
}
void hello()
{
System.out.println("The class C are calling");
}
}
class SuperInheritance
{
public static void main(String args[])
{
C obj=new C();
obj.hello();
}
}
0 comments:
Post a Comment