标签:span imu void sim [] system extends abstract new
abstract class Animal{ abstract void cry(); abstract String getAnimalName(); } class Simulator{ void playSound(Animal animal){ System.out.println("我是"+animal.getAnimalName()); System.out.println("我的叫声是:"); animal.cry(); } } class Dog extends Animal{ void cry(){ System.out.println("汪汪汪"); } String getAnimalName(){ return "小狗"; } } class Cat extends Animal{ void cry(){ System.out.println("喵喵喵"); } String getAnimalName(){ return "小猫"; } } public class Application{ public static void main(String args[]){ Simulator simulator=new Simulator(); simulator.playSound(new Dog()); simulator.playSound(new Cat()); } }
标签:span imu void sim [] system extends abstract new
原文地址:http://www.cnblogs.com/zyb993963526/p/5990676.html