成员变量:编译看左边,执行看左边
成员方法:编译看左边,执行看右边
package Animal;
/**
* @author xujinwei
* @date 2021/4/26 10:11
*/
public class Animal {
public int age = 40;
public void eat(){
System.out.println("动物吃东西");
}
}
package Animal;
/**
* @author xujinwei
* @date 2021/4/26 10:13
*/
public class Cat extends Animal{
public int age = 20;
public int weight = 10;
public void eat(){
System.out.println("猫吃鱼");
}
public void playGame(){
System.out.println("猫捉迷藏");
}
}
package Animal;
/**
* @author xujinwei
* @date 2021/4/26 10:16
*/
public class AnimalDemo {
public static void main(String[] args) {
//有父类引用指向子类对象
Animal a = new Cat();
System.out.println(a.age);
//System.out.println(a.weight);
a.eat();
//a.playGame();
}
}