public class Animaltestdrive{
public static void main(String args[]){
MyanimalList list=new MyanimalList();
Dog a=new Dog();
Cat c=new Cat();
list.add(a);
list.add(c);
}}
public class MyanimalList{
private Animal[] animals = new Animal[5];
private int nextIndex=0;
public void add(Animal a){
if(nextIndex< animals.length){
animals[nextIndex]=a;
System.out.println("Animal added at " + nextIndex);
nextIndex++;
}
}
}
我希望对此进行修改,因此应提供输出: 动物添加为0 在1点添加动物