Google News
logo
CPP - Interview Questions
What is polymorphism in C++?
Polymorphism in simple means having many forms. Its behavior is different in different situations. And this occurs when we have multiple classes that are related to each other by inheritance.
 
For example, think of a base class called a car that has a method called car brand(). Derived classes of cars could be Mercedes, BMW, Audi - And they also have their own implementation of a cars
 
The two types of polymorphism in c++ are :
* Compile-time Polymorphism
* Run-time Polymorphism

(i) Compile-time Polymorphism :
In compile-time polymorphism, we achieve many forms by overloading. Hence, we have an Operator overloading and function overloading. (We have already covered this above)
 
(ii) Run-time Polymorphism :
This is the polymorphism for classes and objects. General idea is that a base class can be inherited by several classes. A base class pointer can point to its child class and a base class array can store different child class objects.
Advertisement