| Polymorphism vs. Inheritance | ||||||||||||||
| What is Polymorphism? | Examples of Polymorphism | |||||||||||||
| Difference between Polymorphism and Inheritance | ||||||||||||||
| What can Polymorphism do? | ||||||||||||||
| Home | ||||||||||||||
| Difference between polymorphism and inheritance
Inheritance is the mechanism which allow to generalize / specialize classes into hierarchy, the base class being the most generic, the classes inheriting from this base class adding some specialization. Example: Polymorphism is the ability to use an object without knowing exactly is type, just by using the base class as a type and being able to call method (virtual method) for it. Having a virtual method StartEngine() on Vehicle, and having this method redefined for all the other class will allow to call that method on a pointer on Vehicle, and the corresponding method in the correct class will be called thanks to polymorphism. |
||||||||||||||