这是我的代码
class Animal{
public int numOf=3;
}
class Dog extends Animal{
public int numOf=4;
}
class TestCase{
public static void main(String[] args){
Animal a = new Dog();
Dog d = new Dog();
System.out.println(a.numOf);
System.out.println(d.numOf);
}
}
当我这样做时a.numOf
,它不应该是 4,就像在 Method 的情况下那样?