Polymorphsim
Polymorphsim
In C++
polymorphism
The word “polymorphism” means having many
forms. In simple words, we can define
polymorphism as the ability of a message to be
displayed in more than one form.
A real-life example of polymorphism is a person
who at the same time can have different
characteristics. A man at the same time is a father,
a husband, and an employee.
So the same person exhibits different behavior in
different situations. This is called polymorphism
Types of Polymorphism
Compile-timePolymorphism
Runtime Polymorphism
Compile-Time Polymorphism
A. Function Overloading
When there are multiple functions with the
same name but different parameters, then the
functions are said to be overloaded, hence
this is known as Function Overloading.
Functions can be overloaded by changing
the number of arguments or/and changing
the type of arguments
Output
value of x is 7
value of x is 9.132
value of x and y is 85, 64
Operator Overloading
C++ has the ability to provide the operators with a
special meaning for a data type, this ability is known
as operator overloading.
For example, we can make use of the addition
operator (+) for string class to concatenate two
strings. We know that the task of this operator is to
add two operands.
So a single operator „+‟, when placed between
integer operands, adds them and when placed
between string operands, concatenates them.
Below is the C++ program to demonstrate operator
overloading: