动物声音“模拟器”(接口与实现)
2017-11-24 17:48
330 查看
interface Animal { abstract void cry(); abstract void getAnimaName(); }
public class Simulator { void playSound(Animal animal){ animal.getAnimaName(); animal.cry(); } }
class Cat implements Animal{ public void cry(){ System.out.println("喵喵喵"); } public void getAnimaName(){ System.out.print("猫:"); } }
class Dog implements Animal{ public void cry(){ System.out.print("汪汪汪"); } public void getAnimaName(){ System.out.print("狗"); } }
public class Application { public static void main(String args[]){ Simulator simulator=new Simulator(); simulator.playSound(new Cat()); simulator.playSound(new Dog()); } }
相关文章推荐
- 用接口实现动物声音模拟器
- Java语言 设计一个动物声音“模拟器”(用接口实现)
- 用接口实现动物声音模拟器
- 第六章作业:动物声音模拟器(接口)
- 接口 动物声音模拟器
- 接口 动物声音模拟器
- 接口 动物声音模拟器
- 接口 动物声音模拟器
- 接口 动物声音模拟器
- 接口 动物声音模拟器
- p160页编程 使用接口实现动物模拟器
- p160页编程 使用接口实现动物模拟器
- 接口:动物声音模拟器
- 接口 动物声音模拟器
- 编程作业160 页 第5题 使用(接口)设计一个动物声音"模拟器",希望模拟器可以模拟许多动物声音
- 利用接口:设计动物声音“模拟器”,希望模拟器可以模拟许多动物的叫声。
- 接口 动物声音模拟器
- 接口 动物声音模拟器
- 作业.设计一个动物声音模拟器(接口)
- 接口 动物声音模拟器