2020
10-08
10-08
Java基于接口实现模拟动物声音代码实例
(1)编写接口Animal(Animal.java)publicinterfaceAnimal{publicabstractvoidcry();publicabstractStringgetAnimalName();}(2)编写模拟类Simulator(Simulator.java)publicclassSimulator{publicvoidplaySound(Animalanimal){System.out.print("正在播放模拟"+animal.getAnimalName()+"的声音:");animal.cry();}}(3)编写Dog类和Cat类(Dog.java、Cat.java)Dog类:publicclassDogimplementsA...
继续阅读 >