pointing subclass object by superclass reference variable
when we can point the object of subclass with superclass reference
variable then why can't we access a subclass method with that reference
variable of superclass..
for eg. following code gives error..
class Child
{
void func()
{
System.out.println("abc");
}
}
class Parent extends Child
{
public static void main(String s[])
{
Child a=new Parent();
a.func();
}
}
No comments:
Post a Comment