What is Polymorphism?

In this lesson, we will be learning about the basics of polymorphism with the implementation details.

The word Polymorphism is a combination of two Greek words, Poly means many and Morph means forms.

Definition

When we say polymorphism in programming that means something which exhibits many forms or behaviors. So far, we have learned that we can add new data and functions to a class through inheritance. But what about if we want our derived class to inherit a method from the base class and have a different implementation for it? That is when polymorphism comes in, a fundamental concept in OOP paradigm.

Shape Class

We are considering here the example of Shape class, which is base class for many shapes like Rectangle and Circle. This class contains a function getArea() which calculates the area for the derived classes.

Get hands-on with 1400+ tech skills courses.