标签:分享图片 技术 eof system images void print img imp
public interface Animal {
void cry();
String getAnimalName();
}
public class Dog implements Animal {
public void cry(){
System.out.println("狗的叫声");
}
public String getAnimalName(){
return "小狗";
}
}
public class Cat implements Animal{
public void cry(){
System.out.println("猫的声音");
}
public String getAnimalName(){
return "小猫";
}
}
public class Simulator {
void playSound(Animal animal){
if(animal instanceof Dog){
animal.cry();
}
if(animal instanceof Cat)
animal.cry();
}
}
public class Application {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Simulator simulator=new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
标签:分享图片 技术 eof system images void print img imp
原文地址:http://www.cnblogs.com/lyly01/p/8001393.html