public class Simulator {
//Simulator s;
public void playSound(Simulator s){
//this.s = s;
//return s;
}
}
public class Dog extends Simulator{
public Dog(){
System.out.println("Dog");
}
}
public class Cat extends Simulator{
public Cat(){
System.out.println("Cat");
}
}
public class Test {
public static void main(String[] args) {
new Simulator().playSound(new Dog());
new Simulator().playSound(new Cat());
}
}
实验结果:
Dog
Cat
不知道是不是这意思。