SlideShare a Scribd company logo
POLYMORPHISM IN C++
Haldia Institute of Technology
Presented By : -
Name Roll no.
Purabi Biswas 14/CS/70
Sanjit Shaw B14/CS/127
Shubham Singhanaia B14/CS/127
(Computer Science & Engineering)
POLYMORPHISM
The process of representing one Form in multiple forms is
known as Polymorphism. Here one form represent original
form or original method always resides in base class and
multiple forms represents overridden method which resides in
derived classes.
Polymorphism is derived from 2 Greek words: poly and
morphs. The word "poly" means many and morphs means
forms.
Real life example of Polymorphism
Suppose if you are in class room that time you behave
like a student, when you are in market at that time you
behave like a customer, when you at your home at that
time you behave like a son or daughter, Here one person
have different-different behaviors.
Type of Polymorphism
 Static polymorphism is also known as early binding and compile-time polymorphism.
In static polymorphism memory will be allocated at compile-time.
 Dynamic polymorphism is also known as late binding and run-time polymorphism. In
dynamic polymorphism memory will be allocated at run-time.
Polymorphism
Static
Function
Overloading
Operator
Overloading
Dynamic
Virtual
Functions
Method Overloading
Whenever same method name is exiting multiple times in the same class with
different number of parameter or different order of parameters or different types of
parameters is known as method overloading.
In next example method "sum()" is present in Addition class with same name but
with different signature or arguments.
Function Overloading Example
class Addition {
public: void sum(int a, int b) {
cout<<"a+b :"<<a+b; } //output :- a+b : 30
void sum(int a, int b, int c) {
cout<<"a+b+c :"<<a+b+c; } //output :- a+b+c : 60
};
int main() {
Addition obj;
obj.sum(10, 20);
cout<<endl;
obj.sum(10, 20, 30); }
Operator Overloading
The process of making an operator to exhibit different behaviors in different
instances is known as operator overloading.
Only predefined operator can be overloaded.
Types Of Operator Overloading
Unary operator overloading.
These Operators have only single operand.
Examples:- ++,--,~,!
Binary operator overloading.
These operators can have two or more operands.
Examples:-+,-,*,/,%,^,=,==,+=,&,&& etc
Operator Overloading Example
class complex{ int main(){
private:: complex c1,c2,c3;
int a,b; c1.set_data(3,4);
public:void set_data(int x,int y){ c2.set_data(5,6);
a=x;b=y;} c3=c1.add+(c2);
void show_data(){ c3.show_data();
cout<<“n a=“<<a<<“b=“<<b;} return 0;}
complex add+(complex c){
complex temp ;
temp.a=a+c.a;
temp.b=b+c.b;
return temp;}};
Virtual Function
A virtual function is a member function that is declared as virtual within a base
class and redefined by a derived class.
 To create virtual function, precede the base version of function’s declaration with
the keyword virtual.
 Here we use a pointer to the base class to refer to all the derived objects.
 The method name and type signature should be same for both base and derived
version of function.
Using Virtual Keyword Example
class A {
public: virtual void show() {
cout<<"Content of base class.n"; }};
class B : public A {
public: void show() {
cout<<"Content of derived class.n"; } };
int main() {
A b,*bptr; //Base class pointer
B d; //Derived class object
bptr = &b;
bptr->show(); //Late Binding Occurs
Bptr=&d;
Bptr->show();
return 0; }
Special Thanks To:-
Mrs. Rajrupa Metia
(Asst. Professor)
Computer Science & Engineering

More Related Content

What's hot

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
Vinod Kumar
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Dr Sukhpal Singh Gill
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
MustafaIbrahimy
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
PRINCE KUMAR
 

What's hot (20)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
OOP java
OOP javaOOP java
OOP java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Inline function
Inline functionInline function
Inline function
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
 

Viewers also liked

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
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
Anil Bapat
 
Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
Dharmisha Sharma
 
polymorphism
polymorphism polymorphism
polymorphism
Imtiaz Hussain
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism023henil
 
A survey of distributed deadlock detection algorithms
A survey of distributed deadlock detection algorithmsA survey of distributed deadlock detection algorithms
A survey of distributed deadlock detection algorithmsanaykh1992
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Nochiketa Chakraborty
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
ushabarad142
 
E wallet
E walletE wallet
Business plan: social networking website
Business plan: social networking website Business plan: social networking website
Business plan: social networking website
Dr. Trilok Kumar Jain
 
E wallet- final
E wallet- finalE wallet- final
E wallet- final
Anshuman Roy
 
Slide 2 data models
Slide 2 data modelsSlide 2 data models
Slide 2 data models
Visakh V
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
Laxman Puri
 
E wallet by amin
E wallet by aminE wallet by amin
E wallet by amin
aminpathan11
 
Underwater wireless communication
Underwater wireless communicationUnderwater wireless communication
Underwater wireless communication
Abhirami P S
 
E wallet
E walletE wallet
E wallet
anuja joshi
 

Viewers also liked (20)

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
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
 
polymorphism
polymorphism polymorphism
polymorphism
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism
 
A survey of distributed deadlock detection algorithms
A survey of distributed deadlock detection algorithmsA survey of distributed deadlock detection algorithms
A survey of distributed deadlock detection algorithms
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
C++ polymorphism
C++ polymorphismC++ polymorphism
C++ polymorphism
 
E wallet
E walletE wallet
E wallet
 
Business plan: social networking website
Business plan: social networking website Business plan: social networking website
Business plan: social networking website
 
E wallet- final
E wallet- finalE wallet- final
E wallet- final
 
Slide 2 data models
Slide 2 data modelsSlide 2 data models
Slide 2 data models
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
E wallet by amin
E wallet by aminE wallet by amin
E wallet by amin
 
Underwater wireless communication
Underwater wireless communicationUnderwater wireless communication
Underwater wireless communication
 
E wallet
E walletE wallet
E wallet
 

Similar to Polymorphism in c++(ppt)

vdocument in_polymorphism-in-cppt_python.pdf
vdocument in_polymorphism-in-cppt_python.pdfvdocument in_polymorphism-in-cppt_python.pdf
vdocument in_polymorphism-in-cppt_python.pdf
parveen204931475
 
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
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
Soba Arjun
 
oops.pptx
oops.pptxoops.pptx
oops.pptx
ASHWINAIT2021
 
Polymorphism ppt
Polymorphism pptPolymorphism ppt
Polymorphism ppt
arunsingh660
 
Polymorphism & inheritence ppt
Polymorphism & inheritence pptPolymorphism & inheritence ppt
Polymorphism & inheritence ppt
arunsingh660
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
riyawagh2
 
Presentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptxPresentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptx
vishwadeep15
 
Polymorphism in c++
Polymorphism in c++Polymorphism in c++
Polymorphism in c++
Dheenadayalan18
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
Suraj Bora
 
What Swift can teach us all
What Swift can teach us allWhat Swift can teach us all
What Swift can teach us all
Pablo Villar
 
Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)
Hassan Hashmi
 
Minimal Introduction to C++ - Part III - Final
Minimal Introduction to C++ - Part III - FinalMinimal Introduction to C++ - Part III - Final
Minimal Introduction to C++ - Part III - Final
Michel Alves
 
2CPP10 - Polymorphism
2CPP10 - Polymorphism2CPP10 - Polymorphism
2CPP10 - Polymorphism
Michael Heron
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
AndiNurkholis1
 
Xamarin: Inheritance and Polymorphism
Xamarin: Inheritance and PolymorphismXamarin: Inheritance and Polymorphism
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 

Similar to Polymorphism in c++(ppt) (20)

vdocument in_polymorphism-in-cppt_python.pdf
vdocument in_polymorphism-in-cppt_python.pdfvdocument in_polymorphism-in-cppt_python.pdf
vdocument in_polymorphism-in-cppt_python.pdf
 
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
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
 
oops.pptx
oops.pptxoops.pptx
oops.pptx
 
Polymorphism ppt
Polymorphism pptPolymorphism ppt
Polymorphism ppt
 
Polymorphism & inheritence ppt
Polymorphism & inheritence pptPolymorphism & inheritence ppt
Polymorphism & inheritence ppt
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Presentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptxPresentation on polymorphism in c++.pptx
Presentation on polymorphism in c++.pptx
 
java poly ppt.pptx
java poly ppt.pptxjava poly ppt.pptx
java poly ppt.pptx
 
Polymorphism in c++
Polymorphism in c++Polymorphism in c++
Polymorphism in c++
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
polymorphism ppt
polymorphism pptpolymorphism ppt
polymorphism ppt
 
What Swift can teach us all
What Swift can teach us allWhat Swift can teach us all
What Swift can teach us all
 
Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)Oopsecondgrouppresentation 180726073512-converted (1)
Oopsecondgrouppresentation 180726073512-converted (1)
 
Minimal Introduction to C++ - Part III - Final
Minimal Introduction to C++ - Part III - FinalMinimal Introduction to C++ - Part III - Final
Minimal Introduction to C++ - Part III - Final
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
2CPP10 - Polymorphism
2CPP10 - Polymorphism2CPP10 - Polymorphism
2CPP10 - Polymorphism
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
 
Xamarin: Inheritance and Polymorphism
Xamarin: Inheritance and PolymorphismXamarin: Inheritance and Polymorphism
Xamarin: Inheritance and Polymorphism
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 

Polymorphism in c++(ppt)

  • 2. Haldia Institute of Technology Presented By : - Name Roll no. Purabi Biswas 14/CS/70 Sanjit Shaw B14/CS/127 Shubham Singhanaia B14/CS/127 (Computer Science & Engineering)
  • 3. POLYMORPHISM The process of representing one Form in multiple forms is known as Polymorphism. Here one form represent original form or original method always resides in base class and multiple forms represents overridden method which resides in derived classes. Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and morphs means forms.
  • 4. Real life example of Polymorphism Suppose if you are in class room that time you behave like a student, when you are in market at that time you behave like a customer, when you at your home at that time you behave like a son or daughter, Here one person have different-different behaviors.
  • 5. Type of Polymorphism  Static polymorphism is also known as early binding and compile-time polymorphism. In static polymorphism memory will be allocated at compile-time.  Dynamic polymorphism is also known as late binding and run-time polymorphism. In dynamic polymorphism memory will be allocated at run-time. Polymorphism Static Function Overloading Operator Overloading Dynamic Virtual Functions
  • 6. Method Overloading Whenever same method name is exiting multiple times in the same class with different number of parameter or different order of parameters or different types of parameters is known as method overloading. In next example method "sum()" is present in Addition class with same name but with different signature or arguments.
  • 7. Function Overloading Example class Addition { public: void sum(int a, int b) { cout<<"a+b :"<<a+b; } //output :- a+b : 30 void sum(int a, int b, int c) { cout<<"a+b+c :"<<a+b+c; } //output :- a+b+c : 60 }; int main() { Addition obj; obj.sum(10, 20); cout<<endl; obj.sum(10, 20, 30); }
  • 8. Operator Overloading The process of making an operator to exhibit different behaviors in different instances is known as operator overloading. Only predefined operator can be overloaded. Types Of Operator Overloading Unary operator overloading. These Operators have only single operand. Examples:- ++,--,~,! Binary operator overloading. These operators can have two or more operands. Examples:-+,-,*,/,%,^,=,==,+=,&,&& etc
  • 9. Operator Overloading Example class complex{ int main(){ private:: complex c1,c2,c3; int a,b; c1.set_data(3,4); public:void set_data(int x,int y){ c2.set_data(5,6); a=x;b=y;} c3=c1.add+(c2); void show_data(){ c3.show_data(); cout<<“n a=“<<a<<“b=“<<b;} return 0;} complex add+(complex c){ complex temp ; temp.a=a+c.a; temp.b=b+c.b; return temp;}};
  • 10. Virtual Function A virtual function is a member function that is declared as virtual within a base class and redefined by a derived class.  To create virtual function, precede the base version of function’s declaration with the keyword virtual.  Here we use a pointer to the base class to refer to all the derived objects.  The method name and type signature should be same for both base and derived version of function.
  • 11. Using Virtual Keyword Example class A { public: virtual void show() { cout<<"Content of base class.n"; }}; class B : public A { public: void show() { cout<<"Content of derived class.n"; } }; int main() { A b,*bptr; //Base class pointer B d; //Derived class object bptr = &b; bptr->show(); //Late Binding Occurs Bptr=&d; Bptr->show(); return 0; }
  • 12. Special Thanks To:- Mrs. Rajrupa Metia (Asst. Professor) Computer Science & Engineering