求大神帮忙改改程序,出现无法从静态上下文中引用非静态变量this不会改
public class Application
{
public static void main(String[] args){
Simulator simulator=new Simulator();
simulator.playSound( new Dog());
simulator.playSound(new Cat());
}
public abstract class Animal
{
public abstract String getName();
public abstract void cry();
}
public class Simulator
{
public void playSound(Animal animal){
System.out.println("现在播放的是"+animal.getName()+"类的声音");
animal.cry();
}
}
public class Dog extends Animal
{
public void cry()
{
System.out.println("汪汪~~~~汪汪");
}
public String getName()
{
return "狗";
}
}
public class Cat extends Animal
{
public void cry()
{
System.out.println("喵喵~~~~喵喵");
}
public String getName()
{
return "猫";
}
}
}