-3
有人可以解释为什么我的检查方法不起作用,因为我不知道错误在哪里。Java检查方法继承
Dog dogArray = new Dog();
Animal[] animals = new Animal[5];
animals [0] = new Dog();
animals [1] = new Cat();
animals [2] = new Wolf();
animals [3] = new Hippo();
animals [4] = new Lion();
for (int i = 0; i < animals.length; i++) {
animals[i].eat();
animals[i].makeNoise();
animals[i].testPolymorphism();
public void checkAnimals() {
if (dogArray.equals(animals[i])) {
System.out.println("DogArray matches Dog i" + i);
}
System.out.println("DogArray doesn't match any animal");
}
}
你在其他方法中声明它。这是行不通的。 – Kayaman
您不能在函数内部创建函数。 – JediBurrell
我不知道你想要在代码中的随机位置声明一个方法,但肯定不是有效的java。 –