代码一:
public static void main(String[] args) {
Dog d = new Dog();
d.eat();
}
}
class Animal {
public void eat(){
System.out.println("动物吃饭");
}
}
class Dog extends Animal{
public void eat(){
super.eat();
System.out.println("狗吃肉");
}
}
输出: 动物吃饭 狗吃肉
代码二:
public static void main(String[] args) {
Dog d = new Dog();
d.eat();
}
}
class Animal {
public void eat(){
System.out.println("动物吃东西");
}
}
class Dog extends Animal {
public void eat(Animal a){
a.eat();
System.out.println("狗吃肉");
}
}
输出 : 动物吃东西