Created
April 3, 2015 20:13
-
-
Save ecornell/83018875ed1abd71f8fc to your computer and use it in GitHub Desktop.
Revisions
-
ecornell created this gist
Apr 3, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ // Animal.java public class Animal { protected String type; public Animal() { type = "Unknown"; } public String getType() { return type; } } // Cat.java public class Cat extends Animal { public Cat() { type = "Cat"; } } // Dog.java public class Dog extends Animal { public Dog() { type = "Dog"; } } // AnimalArray.java import java.util.ArrayList; public class AnimalArray { public static void main(String[] args) { Cat cat = new Cat(); Dog dog = new Dog(); ArrayList<Animal> animalList = new ArrayList<Animal>(); animalList.add(cat); animalList.add(dog); for (Animal animal : animalList) { System.out.println( animal.getType() ); } } } // Output // // Cat // Dog