class A
{
public void show()
{
System.out.println("Super Class");
}
class B Extends A
{
public void show()
{
System.out.println("Sub Class");
}
}
class TestInheritance()
{
public static void main(String args[])
{
A a=new A();
B b=new B();
a.show();
b.show();
}
}
Note: When you change the access specifier of the overridden method in the subclass then it gives an compile time error i.e. u can't reduce the visibility.
No comments:
Post a Comment