0% found this document useful (0 votes)
2 views7 pages

Polymorphsim

Polymorphism in C++ refers to the ability of a message to be displayed in multiple forms, exemplified by a person who can simultaneously fulfill different roles. There are two main types of polymorphism: compile-time and runtime, with compile-time polymorphism including function overloading and operator overloading. Function overloading allows multiple functions with the same name but different parameters, while operator overloading enables operators to have special meanings for different data types.

Uploaded by

sufiyan siddique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Polymorphsim

Polymorphism in C++ refers to the ability of a message to be displayed in multiple forms, exemplified by a person who can simultaneously fulfill different roles. There are two main types of polymorphism: compile-time and runtime, with compile-time polymorphism including function overloading and operator overloading. Function overloading allows multiple functions with the same name but different parameters, while operator overloading enables operators to have special meanings for different data types.

Uploaded by

sufiyan siddique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Polymorphism

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:

You might also like