0% found this document useful (0 votes)
205 views

Polymorphism: Pointers and Polymorphism in C++

The document discusses two types of polymorphism in C++: static/compile-time polymorphism and dynamic/run-time polymorphism. Static polymorphism includes function overloading and operator overloading, which are resolved at compile time. Dynamic polymorphism uses virtual functions, which are resolved at run-time through late binding. The key difference is that static polymorphism is resolved at compile time while dynamic polymorphism is resolved at run time.

Uploaded by

Sahil Gangurde
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
205 views

Polymorphism: Pointers and Polymorphism in C++

The document discusses two types of polymorphism in C++: static/compile-time polymorphism and dynamic/run-time polymorphism. Static polymorphism includes function overloading and operator overloading, which are resolved at compile time. Dynamic polymorphism uses virtual functions, which are resolved at run-time through late binding. The key difference is that static polymorphism is resolved at compile time while dynamic polymorphism is resolved at run time.

Uploaded by

Sahil Gangurde
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Pointers And Polymorphism In C++

Introduction Of Polymorphism, Types Of Polymorphism

POLYMORPHISM
T Y P E S O F P O LY M O R P H I S M
 What Is Polymorphism?
• Polymorphism Is The Combination Of Two Greek Words,
Poly Means : Many
Morphism Means :Forms
• Its stands for “same name multiple forms”.
• It means more than one function with same name ,with different working.
• We can define multiple things, with same name in a program for different purpose.

 EXAMPLE

int main()
{
triangle t;
rectangle r;
t.draw (a, b, c);
r.draw (e, f);
}
Function draw() shows the property of Polymorphism it will behave differently with object “t” and
object
“r”.
 Real Life Example Of Polymorphism

• So The Same Person Posses Different Behavior In Different Situations. This Is Called
Polymorphism. 

 Advantages:
1. It helps programmers reuse the code and classes once written.
2. Single variable name can be used to store variables of multiple data types.
 TYPES OF POLYMORPHISM
1. COMPILE TIME OR STATIC POLYMORPHISM(STATIC)
• Those Operations That Take Place During The Compile Time Are Called Static Or Compile Time
Polymorphism.

1. Function Overloading:

 When There Are Multiple Functions With Same Name But Different Parameters Then These Functions Are
Said To Be Overloaded. Functions Can Be Overloaded By Change In Number Of Arguments Or/And Change
In Type Of Arguments.

2. Operator Overloading:

C++ Also Provide Option To Overload Operators. For Example, We Can Make The Operator (‘+’) For
String Class To Concatenate Two Strings. We Know That This Is The Addition Operator Whose Task Is To
Add Two Operands. So A Single Operator ‘+’ When Placed Between Integer Operands , Adds Them And
When Placed Between String Operands, Concatenates Them.
2. RUN TIME POLYMORPHISM (DYNAMIC)) :
• Runtime Polymorphism Is Also Known As Dynamic Polymorphism Or Late Binding. In
Runtime Polymorphism, The Function Call Is Resolved At Run Time.

2.1 Virtual Functions:

A Virtual Function Is Another Way Of Implementing Run-time Polymorphism In C++. It Is A Special Function
Defined In A Base Class And Redefined In The Derived Class. To Declare A Virtual Function, You Should Use
The Virtual Keyword. The Keyword Should Precede The Declaration Of The Function In The Base Class.
keyword ex: ->
 Difference Between Static And Dynamic Polymorphism

STATIC POLYMORPHISM DYNAMIC POLYMORPHISM


1. A type of polymorphism that collect the 1. A type of polymorphism that collects the
informationto call a method during compile time. information to call a method during run time.
2. Occurs at compile time. 2. Occurs at run time.
3. Known as static binding and early binding. 3. Known as dynamic binding and late binding.
4. Execution speed is high. 4. Execution speed is low.
5. Method overloading is an example of static binding. 5. Method overriding is an example of dynamic binding.
THANK YOU

You might also like