/** * Shelter -- There are lots of things to complain about here but this * is just supposed to be a simple example of the use of inheritance * @author gtowell * Created: Jan 2020 * Modified: Sep 2020 */ public class Shelter { // All of the animals in the shelter private Animal[] animals; // The number of animls in the shelter private int animalCount; /** * Initialize the shelter */ public Shelter() { animals = new Animal[100]; animalCount=0; } // Set accessor, no comment needed public void addAnimal(Animal animal) { animals[animalCount++]=animal; } //get accessor, no comment needed public Animal getAnimal(int location) { return animals[location]; } public static void main(String[] args) { Shelter shelter = new Shelter(); shelter.addAnimal(new Dog()); shelter.addAnimal(new Cat()); Animal aa = shelter.getAnimal(1); if (aa instanceof Cat) { Cat c = (Cat)shelter.getAnimal(1); //Danger here System.out.println(c); }}}