Skip to main content

Polymorphism

Polymorphism means having the ability to have different forms at the same time.

In a real-life scenario, a lady may be a mother, daughter, employer, wife and also an entrepreneur. In this case, the same person displays different behavior according to the situations she handles. This is called polymorphism. Another example is the gears in the car. Depending upon the gear applied the speed of the car is controlled or changed. So the In OOP the polymorphism is important as it allows an action to perform in different ways. The polymorphism is performed in two different ways.

Method overloading

This type has more than one method with the same name but different behavior. The same name methods behave differently according to the parameter passed to them. This is also called as static polymorphism as the method to be invoked is already decided during compilation.

Method overriding

This type allows the method in the derived class is overridden the implementation of the base class. This scenario is resolved during run-time and thus is also known as dynamic polymorphism.