抽象类String类型方法无法正常输出

问题遇到的现象和发生背景

用抽象类定义的字符串方法返回时无法输出

用代码块功能插入代码,请勿粘贴截图

public abstract class Animal {
abstract String cry();//这一行的cry方法无法正常输出
abstract String getAnimalName();
}
public class Application {
public static void main(String[] args) {
Simulator simulator = new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
//模拟器
public class Simulator {
void playSound(Animal animal) {
animal.cry();
System.out.println("这是"+animal.getAnimalName()+"的声音");
}
}

public class Dog extends Animal{
@Override
String cry() {
return "“汪汪!”——";//无法正常返回
}
@Override
String getAnimalName() {
return "金毛";
}
}
public class Cat extends Animal{//继承Animal类的Cat类
@Override
String cry() {
return " “喵喵”—";//无法正常返回
}

@Override
String  getAnimalName() {
    return "银渐层猫";
}

}

运行结果及报错内容

img

我的解答思路和尝试过的方法

用void类型方法可以 ,用St 类型不可以阿

img


这里不要用return,System.out.println输出试试,因为你主函数里只是调用了,没有接收返回值。