当我们可以用超类引用变量指向子类的对象时,为什么我们不能用超类的引用变量访问子类方法..
例如。以下代码给出错误..
class Parent
{
int a;
}
class Child extends Parent
{
void func()
{
System.out.println("abc");
}
public static void main(String s[])
{
Parent a=new Child();
a.func();
}
}