class A
{
}
class B extends A
{
void x()
{
System.out.println("method x");
}//child specific behaviour.
}
class test
{
public static void main(String args[])
{
A a=new B();//super class reference referring to sub class object.
a.x();
}
}
A)
The above program causes compilation error.
->child specific behavior means that method behavior should not contain in super class.
->only overridden methods are called by super class reference which is holding the address of child class.
->even though super class reference can refer to the sub class object. Using class reference child specific (non-overriding) methods can’t be called. In the above example “x()” is not overriding method.
Comments
Post a Comment