- Having many forms.
- “Polymorphism means that a variable of a supertype can refer to a subtype object” pg 425
- Allows us to deal with the diverse (but related) members of a group in a general way.
- Polymorphism means that a variable of a supertype can refer to a subtype object.
- Animal, Fish, Bird, Dog example – note that Animal is not abstract
Bird, Dog, Fish“is-a”
- Use the “is-a” test: <object’s class name> always “is-a” <variable type>
Animal a1 = new Fish();
- We can assign or substitute a member of a subclass for a parent class but not vice-versa
- Dynamic Binding (11.8): binding of which type of object is “in there” and influences the method call; is deferred until run-time.
- Dynamic animal creation example (array of Animals)
- “A method can be implemented in several classes along the inheritance chain. The JVM decides which method is invoked.” pg. 425 (11th edition)