Polymorphism is the Greek word for many-shaped and applies to OOP in two distinct ways:
- Derived class objects are treated the same as parent class objects. For example, an array of Character objects could also store Paladin objects, as they derive from Character.
- Parent classes can mark methods as virtual, meaning that their instructions can be modified by derived classes using the override keyword. In the case of Character and Paladin, it will be useful if we could debug different messages from PrintStatsInfo for each one.
Polymorphism allows derived classes to keep the structure of their parent class while also having the freedom to tailor actions to fit their specific needs. Let's take this new knowledge and apply it to our character debug method.