案例分析

基于下面的代码

Animal.java

1 2 3 4 5 6
public class Animal { public int age; public void eat() { System.out.println("Animal eat()"); }}

Person.java

1 2 3 4 5 6 7 8 9 10
public class Person { public int age; public double balance; public void eat() { System.out.println("Person eat()"); } public void work() { System.out.println("Person work()"); }}

Dog.java

1 2 3 4 5 6 7 8 9
public class Dog { public int age; public void eat() { System.out.println("Dog eat()"); } public void bark() { System.out.println("Dog bark()"); }}

Zoo.java

1 2 3 4 5 6 7 8 9 10 11 12
public class Zoo { public static void main(String[] args) { new Zoo().run(); } public void run() { Dog dog = new Dog(); Person person = new Person(); dog.eat(); person.eat(); }}

问题

age 和 eat 在 Person / Dog / Animal 中都有

ZZAX 微信公众

文档一更新,立刻告诉你