- 编写抽象类Animal
Animal抽象类有两个抽象方法cry()和getAnimalName(),即要求各种具体的动物给出自己的叫声和种类名称 - 编写模拟器类Simulator 该类有一个playSound(Animal
animal)方法,该方法的参数是Animal类型,即参数animal可以调用Animal的子类重写的cry()方法播放具体动物的声音,调用子类重写的getAnimalName()方法显示动物种类的名称。 - 编写Animal的子类:Dog和Cat类
- 编写主类Application(用户程序) 在主类Application的main方法中至少包含如下代码:
Simulator simulator = new Simulator();
simulator.playSound(new Dog());/*转载请说明出处*/
simulator.playSound(new Cat());
Animal.java
public abstract class