Storing Mutiple Classes/Data Types in a Linked List
Is the following possible?
I have 2 classes that extend a parent class;
Animal - the parent class
Dog - extends animal
Cat - extends animal
Now from another class in the package I create a linked list, say myanimals, and I want to store both Dog and Cat in myanimals.
I then want to iterate through the list and if the type execute a method that is present in both of the Dog and Cat classes.
Is it possible to do this or does a list only contain one data type? I have been playing with attempting to do this and I can not seem to find a way to do it.