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
Polymorphism
PPTX
polymorphism
PPT
Cocomo model
PDF
Wifi Direct Based Chat And File Transfer Android Application
PDF
Requirements engineering with UML [Software Modeling] [Computer Science] [Vri...
PDF
Operator Overloading in C++
PPTX
Web services SOAP
PDF
TOC(CS-501) (19-49).pdf
Polymorphism
polymorphism
Cocomo model
Wifi Direct Based Chat And File Transfer Android Application
Requirements engineering with UML [Software Modeling] [Computer Science] [Vri...
Operator Overloading in C++
Web services SOAP
TOC(CS-501) (19-49).pdf

What's hot (20)

PPTX
Polymorphism
PDF
Polymorphism in oop
PPTX
Function overloading and overriding
PPTX
Polymorphism
PPT
Basic concept of OOP's
PPTX
PPTX
Access specifier
PPT
Basic concepts of object oriented programming
PDF
Polymorphism
PDF
Function overloading ppt
PPTX
Inheritance ppt
PPT
friend function(c++)
PPTX
OPERATOR OVERLOADING IN C++
PPTX
INLINE FUNCTION IN C++
PPTX
Exception handling c++
PPTX
Polymorphism in c++(ppt)
PPT
Data members and member functions
PPTX
Multiprogramming&timesharing
PPTX
Functions in c++
PPTX
Multiple inheritance in c++
Polymorphism
Polymorphism in oop
Function overloading and overriding
Polymorphism
Basic concept of OOP's
Access specifier
Basic concepts of object oriented programming
Polymorphism
Function overloading ppt
Inheritance ppt
friend function(c++)
OPERATOR OVERLOADING IN C++
INLINE FUNCTION IN C++
Exception handling c++
Polymorphism in c++(ppt)
Data members and member functions
Multiprogramming&timesharing
Functions in c++
Multiple inheritance in c++
Ad

Similar to Polymorphism and its types (20)

PPTX
11.C++Polymorphism [Autosaved].pptx
PDF
polymorphism.pdf
PPTX
Polymorphism
PPTX
polymorphism and virtual function
PDF
Comparison between runtime polymorphism and compile time polymorphism
PPTX
Polymorphism Using C++
PPTX
Oop lecture 06
PPTX
Presentation on polymorphism in c++.pptx
PPTX
C++ first s lide
PPSX
Polymorphism
PPTX
C++ concept of Polymorphism
PDF
Polymorphism
PDF
Unit3_OOP-converted.pdf
PPTX
Polymorphism
PDF
polymorphism-17013114666666666653806.pdf
PPT
Polymorphism
PDF
polymorphism for b.tech iii year students
PPTX
Polymorphism In c++
PPTX
Polymorphism
PPTX
Polymorphism in c++
11.C++Polymorphism [Autosaved].pptx
polymorphism.pdf
Polymorphism
polymorphism and virtual function
Comparison between runtime polymorphism and compile time polymorphism
Polymorphism Using C++
Oop lecture 06
Presentation on polymorphism in c++.pptx
C++ first s lide
Polymorphism
C++ concept of Polymorphism
Polymorphism
Unit3_OOP-converted.pdf
Polymorphism
polymorphism-17013114666666666653806.pdf
Polymorphism
polymorphism for b.tech iii year students
Polymorphism In c++
Polymorphism
Polymorphism in c++
Ad

Recently uploaded (20)

DOCX
573137875-Attendance-Management-System-original
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Geodesy 1.pptx...............................................
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Total quality management ppt for engineering students
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Artificial Intelligence
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Fundamentals of Mechanical Engineering.pptx
573137875-Attendance-Management-System-original
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Geodesy 1.pptx...............................................
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Total quality management ppt for engineering students
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Artificial Intelligence
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Safety Seminar civil to be ensured for safe working.
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Embodied AI: Ushering in the Next Era of Intelligent Systems
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Fundamentals of Mechanical Engineering.pptx

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.