I have an ArrayList of animals on land. All animals are of different classes, that extend an abstract superclass called Animal. They all have methods such as eat, walk, sleep, etc., but only the Bird class has the method fly.
How can I call the fly method on all Bird objects in the ArrayList?
public class Land{
ArrayList<Animal> landAnimals = new ArrayList<Animal>();
Land(Bird bird, Bird bird2, Bird bird3, Cat cat, Mouse mouse, Dog dog, Dog dog2){
landAnimals.add(bird);
landAnimals.add(cat);
landAnimals.add(mouse);
landAnimals.add(bird2);
landAnimals.add(dog);
landAnimals.add(bird3);
landAnimals.add(dog2);
}
public void animalsWalk(){
int size=landAnimals.size();
for (int count=0; count<size; count++){
landAnimals.walk();
}
}
public void birdsFly(){
//How do I make birds in the arraylist fly?
}
}