Zoo zoo = new Zoo(); //父类实例对象
Parrot parrot = new Parrot(); //子类实例对象
Tortise tortise = new Tortise(); //子类实例对象
zoo.free(parrot); // <–
zoo.free(tortise); // <–
package Test001;
abstract class Animal {
public abstract void move();
}
class Parrot extends Animal {
public void move() {
System.out.println("鹦鹉正在飞行......");
}
}
class Tortise extends Animal {
public void move() {
System.out.println("乌龟正在爬行 ......");
}
}
public class Zoo {
public void free(Animal animal) {
animal.move();
}
public static void main(String[] args) {
Zoo zoo = new Zoo();
Parrot parrot = new Parrot();
Tortise tortise = new Tortise();
zoo.free(parrot);
zoo.free(tortise);
}
}