SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
1

POLYMORPISM
BY
IMTIAZ HUSSAIN
What is Meant By Polymorphism?


It is a Greek word.



Poly mean many.



Morphism mean forms.



In programing Polymorphism is the ability for objects of different
classes related by inheritance to response differently to the same
function call.

2
What is Polymorphism in OOP?


After the inheritance it is another most important feature of OOP.



In polymorphism, the member functions with same name are define
in base class and also in each derived class.



Polymorphism is use to keep the interface of base class to its derived
classes.



Polymorphism can be achieved by mean of virtual functions.



In polymorphism one pointer to a base class object may also point
any object of its derived class.

3
How can we access the member
of class?


The member of a class can be access through pointer to the class.



General syntax;
P -> member class;






P is pointer to object.
-> is member access operator.
Member class. It is the member of the object;

4
Simple program to access member
of class;
void show()


{



#include<iostream.h>





#include<conio.h>



cout<<"Your name is "<<name;



class data



cout<<"Your age is "<<age;



}



{



private:





};



main()

char name[12];



{



int age;





public:



void input(){





cout<<"Entr your name“;
cin>>name;
cout<<"Enter your age"; cin>>age;}

data obj,*j;
j=&obj;
j->input();



j->show();



getch();



}

5
Polymorphism

Early Binding
OR
Static
Binding
OR
Static
Polymorphism

LATE Binding
OR
DYNAMIC
Binding
OR
dynamic
Polymorphism

6
Early Binding



The Events That Takes Place At Compile Time Is Called Early Binding.



Also Called Static Binding.



Information Required To Call A Function Is Known At Compile Time.

7
Early Binding Example
#include<iostream.h>

8

class C: public A{
public:

#include<conio.h>

void show()

class A

{

cout<<"This Is Second Derived Class "<<endl; }

};

public:

void main() {

void show() {
cout<<"This Is Base Class "<<endl;

}

};

A *ptr;
B
C

class B: public A

C1;
C2;

ptr=&C1;

{

ptr->show();

public:

void show()

ptr=&C2;

{

cout<<"This Is First Derived Class "<<endl; }

{

ptr->show();
Virtual Function


Special Type Function.



Can Be Define In Both Derived And Base Class.



Its Name Will Be Same In Every Class.



Definition May Be Different.



In Derived Classes It Will Be Executed Through Pointer Of Its Base
Class.



It is Declared By Keyword Virtual.



A Redefined Function Is Said To Override The Base Class Function.

9
Late Binding



The Events That Takes Place In Execution Time Is Called Late Binding.



In Late Binding At The Compile Time Compiler Does Not Know Which
Message Should Compiler Will Respond Because The Type Of Pointer
Is Unknown At Compile Time.



It Depending Upon The Contents In Pointer During Execution Time Of
Program.

10
Late Binding Example

11

class C: public A{

#include<iostream.h>

public:

#include<conio.h>

void show()

class A
{

void main() {

virtual void show() {
cout<<"This Is Base Class "<<endl;

A *ptr;

}

B

};

C

class B: public A

C2;

ptr->show();

public:

ptr=&C2;

{

cout<<"This Is First Derived Class "<<endl;
};

C1;

ptr=&C1;

{
void show()

cout<<"This Is Second Derived Class "<<endl; }

};

public:

}

{

ptr->show();

getch(); }
Pure Virtual Function


The virtual function that is only declare But Not Define In The In The
Base Class.



General Syntax:




virtual function_name()=0;
The class that contains the pure virtual function exists only to act as
base or parent classes.

12
Abstract Base Class


The base class that has one or more pure virtual function is called
the abstract base class.



These classes designed as a framework or layout for derived classes



An abstract base class cannot be instantiated



i.e.



An object of its type cannot be defined but a pointer to an abstract
base class can be defined.

13
Concrete Derived Class


The derived class that does not have any pure virtual function is
called concrete derived class.



The pure virtual function of the abstract base class is implemented in
the concrete derived class.



The derived classes usually have their own versions of the virtual
functions

14
15

THANKs

Good
Luck

More Related Content

What's hot (20)

PPTX
Polymorphism
Ahmed Za'anin
 
PDF
Polymorphism in oop
MustafaIbrahimy
 
PDF
Polymorphism
Raffaele Doti
 
PDF
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
PPTX
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
ODP
OOP java
xball977
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Java abstract class & abstract methods
Shubham Dwivedi
 
PPTX
Constructor and destructor
Shubham Vishwambhar
 
PDF
Java threads
Prabhakaran V M
 
PPTX
Applets in java
Wani Zahoor
 
PPT
Object and class relationships
Pooja mittal
 
PPT
Operator Overloading
Nilesh Dalvi
 
PDF
Polymorphism In Java
Spotle.ai
 
PPTX
Java package
CS_GDRCST
 
PDF
Method Overloading In Java
CharthaGaglani
 
PPT
Inheritance in java
Lovely Professional University
 
PPTX
Java program structure
Mukund Kumar Bharti
 
PDF
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
Polymorphism
Ahmed Za'anin
 
Polymorphism in oop
MustafaIbrahimy
 
Polymorphism
Raffaele Doti
 
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
OOP java
xball977
 
Java interfaces
Raja Sekhar
 
Java abstract class & abstract methods
Shubham Dwivedi
 
Constructor and destructor
Shubham Vishwambhar
 
Java threads
Prabhakaran V M
 
Applets in java
Wani Zahoor
 
Object and class relationships
Pooja mittal
 
Operator Overloading
Nilesh Dalvi
 
Polymorphism In Java
Spotle.ai
 
Java package
CS_GDRCST
 
Method Overloading In Java
CharthaGaglani
 
Inheritance in java
Lovely Professional University
 
Java program structure
Mukund Kumar Bharti
 
Access specifiers (Public Private Protected) C++
vivekkumar2938
 
Static Data Members and Member Functions
MOHIT AGARWAL
 

Viewers also liked (7)

PPTX
Polymorphism
Kumar Gaurav
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
DOC
Cocrystal review 2011
Simon Curtis
 
PPT
Polymorphism
Duane Wesley
 
PPTX
Inheritance
Sapna Sharma
 
PPTX
M.PHARM_ Rupsa Ghosh
university of pune
 
PPTX
Seminar on polymorphism
023henil
 
Polymorphism
Kumar Gaurav
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
Cocrystal review 2011
Simon Curtis
 
Polymorphism
Duane Wesley
 
Inheritance
Sapna Sharma
 
M.PHARM_ Rupsa Ghosh
university of pune
 
Seminar on polymorphism
023henil
 
Ad

Similar to polymorphism (20)

PDF
polymorpisum-140106223024-phpapp01.pdf
BapanKar2
 
PPTX
polymorphism ppt
sheetal singh
 
PPT
Virtual Function and Polymorphism.ppt
ishan743441
 
PDF
polymorphism for b.tech iii year students
Somesh Kumar
 
PPT
Polymorphism in C++ for beginners reference
21pd23
 
PPTX
OOPS & C++(UNIT 4)
Dr. SURBHI SAROHA
 
PPTX
6. Virtual base class.pptx and virtual function
archana22486y
 
PPT
Virtual Function
Carelon Global Solutions
 
PPTX
Polymorphism
prabhat kumar
 
PDF
Object Oriented Programming (OOP) using C++ - Lecture 4
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
PPTX
Inheritance, Polymorphism, and Virtual Functions.pptx
MrNikhilMohanShinde
 
PPT
VIRTUAL FUNCTIONS c++ -POLYMORPHISM.ppt
blindlove32538210
 
PPTX
B.sc CSIT 2nd semester C++ Unit6
Tekendra Nath Yogi
 
PPTX
Virtual function
zindadili
 
PPTX
Object Oriented Programming using C++: Ch11 Virtual Functions.pptx
RashidFaridChishti
 
PDF
polymorphism-17013114666666666653806.pdf
kashafishfaq21
 
PPTX
Polymorphism
Nochiketa Chakraborty
 
PPTX
Polymorphism
Prof .Pragati Khade
 
PPT
Lab3
karan saini
 
PPTX
Virtual, Pure Virtual functions and Abstract class.pptx
ammarjafri1997
 
polymorpisum-140106223024-phpapp01.pdf
BapanKar2
 
polymorphism ppt
sheetal singh
 
Virtual Function and Polymorphism.ppt
ishan743441
 
polymorphism for b.tech iii year students
Somesh Kumar
 
Polymorphism in C++ for beginners reference
21pd23
 
OOPS & C++(UNIT 4)
Dr. SURBHI SAROHA
 
6. Virtual base class.pptx and virtual function
archana22486y
 
Virtual Function
Carelon Global Solutions
 
Polymorphism
prabhat kumar
 
Object Oriented Programming (OOP) using C++ - Lecture 4
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Inheritance, Polymorphism, and Virtual Functions.pptx
MrNikhilMohanShinde
 
VIRTUAL FUNCTIONS c++ -POLYMORPHISM.ppt
blindlove32538210
 
B.sc CSIT 2nd semester C++ Unit6
Tekendra Nath Yogi
 
Virtual function
zindadili
 
Object Oriented Programming using C++: Ch11 Virtual Functions.pptx
RashidFaridChishti
 
polymorphism-17013114666666666653806.pdf
kashafishfaq21
 
Polymorphism
Nochiketa Chakraborty
 
Polymorphism
Prof .Pragati Khade
 
Virtual, Pure Virtual functions and Abstract class.pptx
ammarjafri1997
 
Ad

Recently uploaded (20)

PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 

polymorphism

  • 2. What is Meant By Polymorphism?  It is a Greek word.  Poly mean many.  Morphism mean forms.  In programing Polymorphism is the ability for objects of different classes related by inheritance to response differently to the same function call. 2
  • 3. What is Polymorphism in OOP?  After the inheritance it is another most important feature of OOP.  In polymorphism, the member functions with same name are define in base class and also in each derived class.  Polymorphism is use to keep the interface of base class to its derived classes.  Polymorphism can be achieved by mean of virtual functions.  In polymorphism one pointer to a base class object may also point any object of its derived class. 3
  • 4. How can we access the member of class?  The member of a class can be access through pointer to the class.  General syntax; P -> member class;     P is pointer to object. -> is member access operator. Member class. It is the member of the object; 4
  • 5. Simple program to access member of class; void show()  {  #include<iostream.h>   #include<conio.h>  cout<<"Your name is "<<name;  class data  cout<<"Your age is "<<age;  }  {  private:   };  main() char name[12];  {  int age;   public:  void input(){   cout<<"Entr your name“; cin>>name; cout<<"Enter your age"; cin>>age;} data obj,*j; j=&obj; j->input();  j->show();  getch();  } 5
  • 7. Early Binding  The Events That Takes Place At Compile Time Is Called Early Binding.  Also Called Static Binding.  Information Required To Call A Function Is Known At Compile Time. 7
  • 8. Early Binding Example #include<iostream.h> 8 class C: public A{ public: #include<conio.h> void show() class A { cout<<"This Is Second Derived Class "<<endl; } }; public: void main() { void show() { cout<<"This Is Base Class "<<endl; } }; A *ptr; B C class B: public A C1; C2; ptr=&C1; { ptr->show(); public: void show() ptr=&C2; { cout<<"This Is First Derived Class "<<endl; } { ptr->show();
  • 9. Virtual Function  Special Type Function.  Can Be Define In Both Derived And Base Class.  Its Name Will Be Same In Every Class.  Definition May Be Different.  In Derived Classes It Will Be Executed Through Pointer Of Its Base Class.  It is Declared By Keyword Virtual.  A Redefined Function Is Said To Override The Base Class Function. 9
  • 10. Late Binding  The Events That Takes Place In Execution Time Is Called Late Binding.  In Late Binding At The Compile Time Compiler Does Not Know Which Message Should Compiler Will Respond Because The Type Of Pointer Is Unknown At Compile Time.  It Depending Upon The Contents In Pointer During Execution Time Of Program. 10
  • 11. Late Binding Example 11 class C: public A{ #include<iostream.h> public: #include<conio.h> void show() class A { void main() { virtual void show() { cout<<"This Is Base Class "<<endl; A *ptr; } B }; C class B: public A C2; ptr->show(); public: ptr=&C2; { cout<<"This Is First Derived Class "<<endl; }; C1; ptr=&C1; { void show() cout<<"This Is Second Derived Class "<<endl; } }; public: } { ptr->show(); getch(); }
  • 12. Pure Virtual Function  The virtual function that is only declare But Not Define In The In The Base Class.  General Syntax:   virtual function_name()=0; The class that contains the pure virtual function exists only to act as base or parent classes. 12
  • 13. Abstract Base Class  The base class that has one or more pure virtual function is called the abstract base class.  These classes designed as a framework or layout for derived classes  An abstract base class cannot be instantiated  i.e.  An object of its type cannot be defined but a pointer to an abstract base class can be defined. 13
  • 14. Concrete Derived Class  The derived class that does not have any pure virtual function is called concrete derived class.  The pure virtual function of the abstract base class is implemented in the concrete derived class.  The derived classes usually have their own versions of the virtual functions 14