We now continue our study of object-oriented programming by explaining and demonstrating polymorphism with inheritance hierarchies. Polymorphism enables us to program in the general rather than program in the specific. In particular, polymorphism enables us to write apps that process objects that share the same base class in a class hierarchy as if they were all objects of the base class.
Let’s consider a polymorphism example. Suppose we create an app that simulates moving several types of animals for a biological study. Classes
Bird represent the types of animals under investigation. Imagine that each class extends base class
Animal, which contains a method
Move and maintains an animal’s current location as ...