更新接口的主函数

master
高宏宇 2 years ago
parent 08a34be4b6
commit d43fee6f51

@ -492,11 +492,13 @@ public class TestEdible {
public static void main(String[] args) {
Object[] objects = { new Tiger(), new Chicken(), new Apple() };
for (int i = 0; i < objects.length; i++) {
if (objects[i] instanceof Edible)
System.out.println(((Edible) objects[i]).howToEat());
if (objects[i] instanceof Edible) {
Edible e = (Edible) objects[i];
System.out.println(e.howToEat());
}
if (objects[i] instanceof Animal) {
System.out.println(((Animal) objects[i]).sound());
Animal a = (Animal) objects[i];
System.out.println(a.sound());
}
}
}

Loading…
Cancel
Save