SlideShare a Scribd company logo
MEWAR INSTITUTE OF MANAGEMENT
SUBMITTED TO: ASHEESH PANDEY SIR
SUBMITTED BY: SHEETAL SINGH
BCA 2ND YEAR
1590409046
POLYMORPHISM
&
ITS TYPE
POLYMORPHISM
• The process of representing one form in multiple forms is known
as polymorphism
• Polymorphism is derived from 2 Greek words: poly and morphs.
The word "poly" means many and morphs means forms. So
polymorphism means many forms
Real life example
HOWCAN WE ACCESS THE MEMBER OF CLASS
The member of class can be access through pointer to the
class
General syntax
P->member class;
P is pointer of object
-> is member access operator
Member class it is the member of the object
POLYMORPHISM
COMPILE TIME
POLYMORPHIS
M
RUN TIME
POLYMORPHIS
M
FUNCTION
OVERLODIN
G
OPERATOR
OVERLODIN
G
VIRTUAL
FUNCTION
COMPILE TIME POLYMORPHISM
• It is also known as static binding, early binding and overloading as
well
• It provides fast execution because known early at compile time
compile time
• Polymorphism is less flexible as all things execute at compile time.
• It is achieved by function overloading and operator overloading
COMPILE TIME POLYMORPHISM
FUNCTION OVERLOADING
• Overloading refers to the use
of the same thing for different
purpose
• Function overloading is a
logical method of calling
several function with different
datatype and argument but
name of function is the same
OPERATOR OVERLOADING
• In C++ the overloading principle
applies not only to functions, but to
operators too.
• Overloaded operator is used to
perform operation on user-defined
data type. For example '+' operator
can be overloaded to perform
addition on various data types, like
for integer, string(concatenation) etc.
RUN TIME POLYMORPHISM
• It is also known as dynamic binding, late binding and overriding as
well
• It provides slow execution as compare to early binding because it
is known at runtime
• Run time polymorphism is more flexible as all things execute at
run time.
• It is achieved by virtual functions and pointers
VIRTUAL FUNCTION
It is a special type of function
It can be declared within base class and redefine by derived class
Its name will be same in every class
In derived class it will be executed through pointer of base class
It is declared by the keyword “virtual”
A redefined function is said to override the base class function
PROGRAM RELATED
TO
VIRTUAL FUNCTION
#include<iostream.h>
class base{
public:
void display()
{cout<<“display base”;}
virtual void show()
{cout<<“nshow base”;}
};
class derived : public
base
{
public:
void display()
{cout<<“n display
derived”;}
void show()
{cout<<“n show derived”;}
};
int main()
{
base b;
derived d;
base*bptr;
cout<<“n bptr points to
base”;
bptr=&b;
bptr->display();
Bptr->show();
Cout<<“n bptr points to
derived”;
Bptr=&d;
Bptr->display();
Bptr->show();
Return 0;
}
OUTPUT
bptr points to base
display base
show case
bptr points to derived
display base
show derived
RULES OF VIRTUAL FUNCTION
• Virtual function must be member of some class
• They can’t static member
• Virtual function can be a friend of another class
• We can’t have virtual constructor but we have virtual destructor
• Virtual function is define in the base class it is not necessary to redefine in the
derived class
PURE VIRTUAL FUNCTION
• Pure virtual function give small definition to the abstract class . we
need at least one pure virtual function to create abstract class
• Pure virtual function must be define outside the function if it will
define inside the function then compiler show error
polymorphism ppt

More Related Content

What's hot

Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
Home
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
Nitesh Dubey
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
Suraj Bora
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Raffaele Doti
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
RAGAVIC2
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
Kavindu Sachinthe
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
Liju Thomas
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
temkin abdlkader
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
Arpita Patel
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Kamal Acharya
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Iqra khalil
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
Python: Polymorphism
Python: PolymorphismPython: Polymorphism
Python: Polymorphism
Damian T. Gordon
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh Dalvi
 

What's hot (20)

Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Array of objects.pptx
Array of objects.pptxArray of objects.pptx
Array of objects.pptx
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Introduction to method overloading &amp; method overriding in java hdm
Introduction to method overloading &amp; method overriding  in java  hdmIntroduction to method overloading &amp; method overriding  in java  hdm
Introduction to method overloading &amp; method overriding in java hdm
 
Python: Polymorphism
Python: PolymorphismPython: Polymorphism
Python: Polymorphism
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 

Viewers also liked

Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
cprogrammings
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Kumar Gaurav
 
Introduction to microsoft word 2007
Introduction to microsoft word 2007Introduction to microsoft word 2007
Introduction to microsoft word 2007
Abdul-rahaman Bin Abubakar Suleman
 
Microsoft word presentation
Microsoft word presentationMicrosoft word presentation
Microsoft word presentation
egirshovich
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
elliehood
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
Mandy Suzanne
 

Viewers also liked (7)

Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Introduction to microsoft word 2007
Introduction to microsoft word 2007Introduction to microsoft word 2007
Introduction to microsoft word 2007
 
Microsoft word presentation
Microsoft word presentationMicrosoft word presentation
Microsoft word presentation
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to polymorphism ppt

OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
SURBHI SAROHA
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Amir Ali
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
PRINCE KUMAR
 
Comparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismComparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphism
CHAITALIUKE1
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
kiran Patel
 
Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01
Engr.Tazeen Ahmed
 
polymorphism OOP.pptx
polymorphism OOP.pptxpolymorphism OOP.pptx
polymorphism OOP.pptx
AssadLeo1
 
polymorphism and virtual function
polymorphism and virtual functionpolymorphism and virtual function
polymorphism and virtual function
Bhanuprataparya
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
riyawagh2
 
Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
Dharmisha Sharma
 
polymorpisum-140106223024-phpapp01.pdf
polymorpisum-140106223024-phpapp01.pdfpolymorpisum-140106223024-phpapp01.pdf
polymorpisum-140106223024-phpapp01.pdf
BapanKar2
 
polymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfpolymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdf
kashafishfaq21
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Nochiketa Chakraborty
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
zindadili
 
Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)
Hassan Hashmi
 
Virtual function
Virtual functionVirtual function
Virtual function
zindadili
 
Polymorphism ppt
Polymorphism pptPolymorphism ppt
Polymorphism ppt
arunsingh660
 
Polymorphism & inheritence ppt
Polymorphism & inheritence pptPolymorphism & inheritence ppt
Polymorphism & inheritence ppt
arunsingh660
 
Oop lecture 06
Oop lecture 06Oop lecture 06
Oop lecture 06
University of Chitral
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
 

Similar to polymorphism ppt (20)

OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
 
Comparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismComparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphism
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01Polymorphism 140527082302-phpapp01
Polymorphism 140527082302-phpapp01
 
polymorphism OOP.pptx
polymorphism OOP.pptxpolymorphism OOP.pptx
polymorphism OOP.pptx
 
polymorphism and virtual function
polymorphism and virtual functionpolymorphism and virtual function
polymorphism and virtual function
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
 
Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
 
polymorpisum-140106223024-phpapp01.pdf
polymorpisum-140106223024-phpapp01.pdfpolymorpisum-140106223024-phpapp01.pdf
polymorpisum-140106223024-phpapp01.pdf
 
polymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdfpolymorphism-17013114666666666653806.pdf
polymorphism-17013114666666666653806.pdf
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Polymorphism ppt
Polymorphism pptPolymorphism ppt
Polymorphism ppt
 
Polymorphism & inheritence ppt
Polymorphism & inheritence pptPolymorphism & inheritence ppt
Polymorphism & inheritence ppt
 
Oop lecture 06
Oop lecture 06Oop lecture 06
Oop lecture 06
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 

polymorphism ppt

  • 1. MEWAR INSTITUTE OF MANAGEMENT SUBMITTED TO: ASHEESH PANDEY SIR SUBMITTED BY: SHEETAL SINGH BCA 2ND YEAR 1590409046
  • 3. POLYMORPHISM • The process of representing one form in multiple forms is known as polymorphism • Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and morphs means forms. So polymorphism means many forms Real life example
  • 4. HOWCAN WE ACCESS THE MEMBER OF CLASS The member of class can be access through pointer to the class General syntax P->member class; P is pointer of object -> is member access operator Member class it is the member of the object
  • 6. COMPILE TIME POLYMORPHISM • It is also known as static binding, early binding and overloading as well • It provides fast execution because known early at compile time compile time • Polymorphism is less flexible as all things execute at compile time. • It is achieved by function overloading and operator overloading
  • 7. COMPILE TIME POLYMORPHISM FUNCTION OVERLOADING • Overloading refers to the use of the same thing for different purpose • Function overloading is a logical method of calling several function with different datatype and argument but name of function is the same OPERATOR OVERLOADING • In C++ the overloading principle applies not only to functions, but to operators too. • Overloaded operator is used to perform operation on user-defined data type. For example '+' operator can be overloaded to perform addition on various data types, like for integer, string(concatenation) etc.
  • 8. RUN TIME POLYMORPHISM • It is also known as dynamic binding, late binding and overriding as well • It provides slow execution as compare to early binding because it is known at runtime • Run time polymorphism is more flexible as all things execute at run time. • It is achieved by virtual functions and pointers
  • 9. VIRTUAL FUNCTION It is a special type of function It can be declared within base class and redefine by derived class Its name will be same in every class In derived class it will be executed through pointer of base class It is declared by the keyword “virtual” A redefined function is said to override the base class function
  • 11. #include<iostream.h> class base{ public: void display() {cout<<“display base”;} virtual void show() {cout<<“nshow base”;} }; class derived : public base { public: void display() {cout<<“n display derived”;} void show() {cout<<“n show derived”;} }; int main() { base b; derived d; base*bptr; cout<<“n bptr points to base”; bptr=&b; bptr->display(); Bptr->show(); Cout<<“n bptr points to derived”; Bptr=&d; Bptr->display(); Bptr->show(); Return 0; }
  • 12. OUTPUT bptr points to base display base show case bptr points to derived display base show derived
  • 13. RULES OF VIRTUAL FUNCTION • Virtual function must be member of some class • They can’t static member • Virtual function can be a friend of another class • We can’t have virtual constructor but we have virtual destructor • Virtual function is define in the base class it is not necessary to redefine in the derived class
  • 14. PURE VIRTUAL FUNCTION • Pure virtual function give small definition to the abstract class . we need at least one pure virtual function to create abstract class • Pure virtual function must be define outside the function if it will define inside the function then compiler show error