SlideShare a Scribd company logo
2
Most read
6
Most read
15
Most read
Polymorphism
Polymorphism means “many forms”.
Polymorphism means ability to take more than one form.
Polymorphism is the ability to use an operator or function in
different ways. Polymorphism gives different meanings or
functions to the operators or functions. Poly, referring too many,
signifies the many uses of these operators and functions. A single
function usage or an operator functioning in many ways can be
called polymorphism. Polymorphism refers to codes, operations or
objects that behave differently in different contexts.
Types of Polymorphism:
• C++ provides two different types of polymorphism.
• Run-time
• Compile-time
Compile Time Polymorphism
• Compile time polymorphism is also known as static binding or early
binding.
Function overloading and Operator overloading are the example of
compile time polymorphism.
It is called compile time polymorphism because which version of
function to invoke is determined by the compiler at compile time
based on number and types of the argument.
Polymorphism and its types
Polymorphism and its types
Function Overloading
In C++, two or more functions can share the same name as
long as their parameter declarations are different.
In this situation, the functions that share the same name are
said to be overloaded, and the process is referred to as
function overloading.
DEFINITION
It is the process of using the same name for two or more
functions.
The secret to overloading is that each redefinition of the
function must use either
• different types of parameters
• different number of parameters.
• The key to function overloading is a function’s argument list.
• A function’s argument list is known as its signature.
Different types of
arguments
Different number of
parameter
void print(int a); void area(float r);
void print (double b); void area(float l, float b);
void print(char c); void area(float a, float b,
float c);
If two function have same number and types
of arguments in the same order, they are said
to have the same signature.
There is no importance to their variable
names.
• void print(int x, float y);
• void print(int p, float q);
are said to have same signature.
Operator Overloading
• It is one type of Static Polymorphism.
• C++ has about 45 operators. These operators are defined for the
fundamental data types (int, float etc).
• While defining a class, we are actually creating a new datatype.
• Most of the C++ operators can be overloaded to apply to our new
class datatype
• Operator overloading is the concept of giving new meaning to an
existing C++ operator.
• When overloaded, the operators are implemented as functions using
the operator keyword.
• For example, the syntax of overloading the addition operator “+”
would be operator+().
• One of the nice features of C++ is that you can give special meanings
to operators, when they are used with user-defined classes. This is
called operator overloading.
• Arithmetic operators overloaded using member function of a class
must have one argument as object of class.
• Arithmetic operators overloaded using friend function of a class must
have two argument
 Can perform variety of
functions with same function
name.
 No need to remember name of
many functions.
 Functions should have
different argument lists.
 Member functions cannot be
overloaded solely on the basis
of one being static and the
other being non static.
Runtime Polymorphism
• When the target object and/or the invoked method is not known at
compile time, so the binding is delayed till runtime. This is called
runtime binding or late binding or runtime Polymorphism.
Compile time Polymorphism Run time Polymorphism
In Compile time Polymorphism, call is resolved
by the compiler.
In Run time Polymorphism, call is not resolved
by the compiler.
It is also known as Static binding, Early
binding and overloading as well.
It is also known as Dynamic binding, Late
binding and overriding as well.
Overloading is compile time polymorphism
where more than one methods share the same
name with different parameters or signature
and different return type.
Overriding is run time polymorphism having
same method with same parameters or
signature, but associated in a class & its
subclass.
It is achieved by function overloading
and operatoroverloading.
It is achieved by virtual
functions and pointers.
It provides fast execution because known
early at compile time.
It provides slow execution as compare to
early binding because it is known at runtime.
Compile time polymorphism is less flexible as
all things execute at compile time.
Run time polymorphism is more flexible as all
things execute at run time.
Polymorphism and its types

More Related Content

PPTX
Train-Ticket_Booking-System-Presentation.pptx
PPTX
Inline function
DOCX
srs for railway reservation system
PPTX
What's New in API Connect & DataPower Gateway in 1H 2018
PPTX
CONTEXT FREE GRAMMAR
PPTX
Wifi & 802.11 Standards
PPTX
Bioequivalence studies
Train-Ticket_Booking-System-Presentation.pptx
Inline function
srs for railway reservation system
What's New in API Connect & DataPower Gateway in 1H 2018
CONTEXT FREE GRAMMAR
Wifi & 802.11 Standards
Bioequivalence studies

What's hot (20)

PPTX
Polymorphism
PPT
Operator Overloading
PPTX
Chapter 07 inheritance
PPTX
Interface in java
PPT
Function overloading(c++)
PPTX
Method overloading
PPTX
Data types in java
PPTX
Exception handling c++
PPTX
Member Function in C++
PPTX
Inheritance in java
PDF
Operator overloading C++
PPT
Introduction to method overloading & method overriding in java hdm
PPTX
Encapsulation C++
PPTX
Templates in C++
PDF
C++ OOPS Concept
PPSX
Break and continue
PPTX
Pointers,virtual functions and polymorphism cpp
PPTX
Pointers in c++
PPTX
JAVA FEATURES
PPTX
File in C language
Polymorphism
Operator Overloading
Chapter 07 inheritance
Interface in java
Function overloading(c++)
Method overloading
Data types in java
Exception handling c++
Member Function in C++
Inheritance in java
Operator overloading C++
Introduction to method overloading & method overriding in java hdm
Encapsulation C++
Templates in C++
C++ OOPS Concept
Break and continue
Pointers,virtual functions and polymorphism cpp
Pointers in c++
JAVA FEATURES
File in C language
Ad

Similar to Polymorphism and its types (20)

PPTX
Presentation on polymorphism in c++.pptx
PPT
Polymorphism
PPTX
POLYMORPHISM
PPTX
C++ first s lide
PDF
Learn C# Programming Polymorphism & Operator Overloading
PPTX
Polymorphism
PPTX
C++ concept of Polymorphism
PPTX
Oop lecture 06
PPTX
oops.pptx
PDF
polymorphism.pdf
PPTX
Polymorphism 140527082302-phpapp01
PPT
OODP UNIT 2 Function overloading
PPTX
Function overloading in c++
PPTX
polymorphism and virtual function
PDF
OOP_UnitIII.pdf
PPTX
Polymorphism
PPTX
11.C++Polymorphism [Autosaved].pptx
PPTX
OOPS & C++(UNIT 4)
PDF
Btech chapter notes batcha ros zir skznzjsbaajz z
PDF
Comparison between runtime polymorphism and compile time polymorphism
Presentation on polymorphism in c++.pptx
Polymorphism
POLYMORPHISM
C++ first s lide
Learn C# Programming Polymorphism & Operator Overloading
Polymorphism
C++ concept of Polymorphism
Oop lecture 06
oops.pptx
polymorphism.pdf
Polymorphism 140527082302-phpapp01
OODP UNIT 2 Function overloading
Function overloading in c++
polymorphism and virtual function
OOP_UnitIII.pdf
Polymorphism
11.C++Polymorphism [Autosaved].pptx
OOPS & C++(UNIT 4)
Btech chapter notes batcha ros zir skznzjsbaajz z
Comparison between runtime polymorphism and compile time polymorphism
Ad

Recently uploaded (20)

PPT
Mechanical Engineering MATERIALS Selection
PPTX
Geodesy 1.pptx...............................................
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
composite construction of structures.pdf
PPTX
Construction Project Organization Group 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
Sustainable Sites - Green Building Construction
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Welding lecture in detail for understanding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
DOCX
573137875-Attendance-Management-System-original
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
PPT on Performance Review to get promotions
Mechanical Engineering MATERIALS Selection
Geodesy 1.pptx...............................................
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
composite construction of structures.pdf
Construction Project Organization Group 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Sustainable Sites - Green Building Construction
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Digital Logic Computer Design lecture notes
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Welding lecture in detail for understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
573137875-Attendance-Management-System-original
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Foundation to blockchain - A guide to Blockchain Tech
PPT on Performance Review to get promotions

Polymorphism and its types

  • 1. Polymorphism Polymorphism means “many forms”. Polymorphism means ability to take more than one form. Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. Poly, referring too many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts.
  • 2. Types of Polymorphism: • C++ provides two different types of polymorphism. • Run-time • Compile-time
  • 3. Compile Time Polymorphism • Compile time polymorphism is also known as static binding or early binding. Function overloading and Operator overloading are the example of compile time polymorphism. It is called compile time polymorphism because which version of function to invoke is determined by the compiler at compile time based on number and types of the argument.
  • 6. Function Overloading In C++, two or more functions can share the same name as long as their parameter declarations are different. In this situation, the functions that share the same name are said to be overloaded, and the process is referred to as function overloading. DEFINITION It is the process of using the same name for two or more functions. The secret to overloading is that each redefinition of the function must use either • different types of parameters • different number of parameters.
  • 7. • The key to function overloading is a function’s argument list. • A function’s argument list is known as its signature. Different types of arguments Different number of parameter void print(int a); void area(float r); void print (double b); void area(float l, float b); void print(char c); void area(float a, float b, float c);
  • 8. If two function have same number and types of arguments in the same order, they are said to have the same signature. There is no importance to their variable names. • void print(int x, float y); • void print(int p, float q); are said to have same signature.
  • 9. Operator Overloading • It is one type of Static Polymorphism. • C++ has about 45 operators. These operators are defined for the fundamental data types (int, float etc). • While defining a class, we are actually creating a new datatype. • Most of the C++ operators can be overloaded to apply to our new class datatype
  • 10. • Operator overloading is the concept of giving new meaning to an existing C++ operator. • When overloaded, the operators are implemented as functions using the operator keyword. • For example, the syntax of overloading the addition operator “+” would be operator+(). • One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloading.
  • 11. • Arithmetic operators overloaded using member function of a class must have one argument as object of class. • Arithmetic operators overloaded using friend function of a class must have two argument
  • 12.  Can perform variety of functions with same function name.  No need to remember name of many functions.
  • 13.  Functions should have different argument lists.  Member functions cannot be overloaded solely on the basis of one being static and the other being non static.
  • 14. Runtime Polymorphism • When the target object and/or the invoked method is not known at compile time, so the binding is delayed till runtime. This is called runtime binding or late binding or runtime Polymorphism.
  • 15. Compile time Polymorphism Run time Polymorphism In Compile time Polymorphism, call is resolved by the compiler. In Run time Polymorphism, call is not resolved by the compiler. It is also known as Static binding, Early binding and overloading as well. It is also known as Dynamic binding, Late binding and overriding as well. Overloading is compile time polymorphism where more than one methods share the same name with different parameters or signature and different return type. Overriding is run time polymorphism having same method with same parameters or signature, but associated in a class & its subclass. It is achieved by function overloading and operatoroverloading. It is achieved by virtual functions and pointers. It provides fast execution because known early at compile time. It provides slow execution as compare to early binding because it is known at runtime. Compile time polymorphism is less flexible as all things execute at compile time. Run time polymorphism is more flexible as all things execute at run time.