A couple of syntax errors to fix:
- Add a semicolon to the end of
animals[0] = new Fish();
- Change
Animal animal[] = new Animal[SIZE];
toAnimal[] animals = new Animal[SIZE];
Also, you should really be doing this in the for
loop:
for(Animal animal : animals){
animal.makeSound();
animal.move();
}
Just hard-coding print statements defeats the purpose of having the Animal
interface, even if Fish
is the only class implementing Animal
at the moment.