C++ Programming - OOPS Concepts - Discussion

Discussion :: OOPS Concepts - General Questions (Q.No.14)


How many types of polymorphisms are supported by C++?

[A]. 1
[B]. 2
[C]. 3
[D]. 4

Answer: Option B


The two main types of polymorphism are run-time (implemented as inheritance and virtual functions), and compile-time (implemented as templates).

M.R.R said: (Apr 26, 2012)  
There are two types
1. Operator overloading
2. Function overloading

Raghav said: (Apr 27, 2012)  
1st is Compile Time Polymorphism and Another is Run Time Polymorphism.

Agilegroup said: (Apr 29, 2012)  
1)Complie time Polymorphism : -

a) Function Overloading
b) Operator Overloading

2) Run-time Polymorphism : -

a) Virtual Functions

Money Chopra said: (May 4, 2012)  
First one is static: function overloading and operator overloading fall under this type of polymorphism.
Second one is dynamic: it is implemented by using virtual functions.

Peeyush said: (May 9, 2012)  
1.Static polymorphism
2.Dynamic polymorphism

Hema Priya said: (May 17, 2012)  
1) Run time polymorphism.
2) Compile time polymorphism.

Rekha said: (May 25, 2012)  
Types of Polymorphism:
1. Static / Compile time / Early binding polymorphism :
a. Function overloading
b. Operator overloading

2. Dynamic / Run time / Late binding:
a. Virtual function

Abhishek said: (May 29, 2012)  
Run time polymorphism & Compile time polymorphism.

Sankararaomajji said: (Nov 22, 2012)  
Compile time polymorphism
- function and operator overloading
- Templates

Run time polymorphism
- function over riding

Gajanan Waghode said: (Jan 13, 2013)  

Polymorphism is the phenomenon where the same message sent to two different objects produces two different set of actions.

Polymorphism is broadly divided into two parts:.

Static polymorphism – exhibited by overloaded functions.

Dynamic polymorphism – exhibited by using late binding.

Static Polymorphism.

Static polymorphism refers to an entity existing in different physical forms simultaneously. Static polymorphism involves binding of functions based on the number, type, and sequence of arguments. The various types of parameters are specified in the function declaration, and therefore the function can be bound to calls at compile time. This form of association is called early binding. The term early binding stems from the fact that when the program is executed, the calls are already bound to the appropriate functions.

The resolution of a function call is based on number, type, and sequence of arguments declared for each form of the function. Consider the following function declaration:.

Void add (int, int) ;.

Void add (float, float) ;.

When the add () function is invoked, the parameters passed to it will determine which version of the function will be executed. This resolution is done at compile time.

Dynamic Polymorphism.

Dynamic polymorphism refers to an entity changing its form depending on the circumstances. A function is said to exhibit dynamic polymorphism when it exists in more than one form, and calls to its various forms are resolved dynamically when the program is executed. The term late binding refers to the resolution of the functions at run-time instead of compile time. This feature increases the flexibility of the program by allowing the appropriate method to be invoked, depending on the context.

Static Vs Dynamic Polymorphism.

Static polymorphism is considered more efficient, and dynamic polymorphism more flexible.

Statically bound methods are those methods that are bound to their calls at compile time. Dynamic function calls are bound to the functions during run-time. This involves the additional step of searching the functions during run-time. On the other hand, no run-time search is required for statically bound functions.

As applications are becoming larger and more complicated, the need for flexibility is increasing rapidly. Most users have to periodically upgrade their software, and this could become a very tedious task if static polymorphism is applied. This is because any change in requirements requires a major modification in the code. In the case of dynamic binding, the function calls are resolved at run-time, thereby giving the user the flexibility to alter the call without having to modify the code.

To the programmer, efficiency and performance would probably be a primary concern, but to the user, flexibility or maintainability may be much more important. The decision is thus a trade-off between efficiency and flexibility.

Sanjeev Kumar said: (Jan 21, 2013)  
There are basically two types of polymorphism:

1) Operator Overloading (same operator can be used to perform different functions).

2) Function Overloading (name of two function can be same but the return type of function of the number of arguments the function have or the types of arguments must be different. ).

Soujanya said: (Mar 21, 2013)  
1. Subtype polymorphism is also known as runtime polymorphism.

2. Parametric polymorphism is also known as compile-time polymorphism.

3. Ad-hoc polymorphism is also known as overloading.

4. Coercion is also known as (implicit or explicit) casting.

Lachu said: (Sep 18, 2013)  
Example for operator overloading:

Using (+)operator we can two numbers and also concat the two string("wel"+"come"="welcome").

Dixit said: (Sep 24, 2013)  
Polymorphism is of 4 types:

1. Subtype polymorphism is also known as runtime polymorphism.

2. Parametric polymorphism is also known as compile-time Polymorphism.

3. Ad-hoc polymorphism is also known as overloading.

4. Coercion is also known as (implicit or explicit) casting.

Nilay Vishwakarma said: (Nov 24, 2013)  
There is a very active debate on whether Ad-Hoc polymorphism is a subset of Parametric polymorphism or not.

Also, Coercion is polymorphism only in type theory and not in C++.

So I too would put my bet on "2".

Rohini said: (Dec 13, 2014)  
*Compile Time Polymorphism:

Function overloading and Operator overloading:

Here we are giving various meanings to the functions and operators (we can't use some special operators).

*Run Time Polymorphism:

It is used in inheritance using the key word "virtual" in base class.

Amol Matre said: (Aug 17, 2015)  
C++ support two types of polymorphism first one is compile time polymorphism and second one is run time polymorphism.

Logi said: (Sep 25, 2016)  
Thanks for the answers with clear explanation.

Suri said: (Feb 16, 2017)  
Thanks for the explanation of the answers.

Please give more example for this.

Bantishrivastava said: (Sep 25, 2018)  
Two types of polymorphism.
1. Runtime polymorphism.
a.virtual class.

2. Compile time polymorphism.
a. Operator overloading.
b. Function overloading.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.