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

PPTX
PPT on Artificial Intelligence(A.I.)
PPTX
AI-03 Problems State Space.pptx
PPTX
Chomsky LAD and UG
PPTX
data abstraction in DBMS
PPTX
Encryption ppt
PPTX
Eating disorders.
PPS
Work Life Balance
PPT on Artificial Intelligence(A.I.)
AI-03 Problems State Space.pptx
Chomsky LAD and UG
data abstraction in DBMS
Encryption ppt
Eating disorders.
Work Life Balance

What's hot (20)

PPTX
Polymorphism
PPTX
Polymorphism
PDF
Polymorphism in oop
PPT
friend function(c++)
PPTX
Function overloading and overriding
PPTX
INLINE FUNCTION IN C++
PPTX
Interfaces in java
PPTX
Super keyword in java
PPTX
Inheritance in JAVA PPT
PPTX
polymorphism ppt
PPTX
Polymorphism presentation in java
PDF
Chapter2 Encapsulation (Java)
PDF
Function overloading ppt
PPTX
07. Virtual Functions
PPTX
Exception handling c++
PPTX
Virtual base class
PDF
Polymorphism in Java
PPTX
Java abstract class & abstract methods
PPS
Interface
PPTX
Polymorphism in c++(ppt)
Polymorphism
Polymorphism
Polymorphism in oop
friend function(c++)
Function overloading and overriding
INLINE FUNCTION IN C++
Interfaces in java
Super keyword in java
Inheritance in JAVA PPT
polymorphism ppt
Polymorphism presentation in java
Chapter2 Encapsulation (Java)
Function overloading ppt
07. Virtual Functions
Exception handling c++
Virtual base class
Polymorphism in Java
Java abstract class & abstract methods
Interface
Polymorphism in c++(ppt)
Ad

Viewers also liked (7)

PPTX
Polymorphism
DOC
Cocrystal review 2011
PPT
Polymorphism
PDF
Polymorphism
PPTX
Inheritance
PPTX
M.PHARM_ Rupsa Ghosh
PPTX
Seminar on polymorphism
Polymorphism
Cocrystal review 2011
Polymorphism
Polymorphism
Inheritance
M.PHARM_ Rupsa Ghosh
Seminar on polymorphism
Ad

Similar to polymorphism (20)

PDF
polymorpisum-140106223024-phpapp01.pdf
PPTX
Polymorphism
PPTX
Polymorphism
PDF
polymorphism-17013114666666666653806.pdf
PPT
polymorphism
PPTX
Virtual function
PPTX
polymorphism OOP.pptx
PDF
polymorphism for b.tech iii year students
PPTX
Inheritance, friend function, virtual function, polymorphism
PPTX
Polymorphism.Difference between Inheritance & Polymorphism
PDF
Inheritance
PDF
polymorphism.pdf
PPTX
OOP interview questions & answers.
PDF
What is Closure and Its Uses in PHP
PPT
Lecture6.ppt
PPT
JavaHTP6e_10.ppt
PPTX
Php oop (1)
PPT
14_inheritance.ppt
PDF
Object Oriented Programming With Real-World Scenario
PPT
The smartpath information systems c plus plus
polymorpisum-140106223024-phpapp01.pdf
Polymorphism
Polymorphism
polymorphism-17013114666666666653806.pdf
polymorphism
Virtual function
polymorphism OOP.pptx
polymorphism for b.tech iii year students
Inheritance, friend function, virtual function, polymorphism
Polymorphism.Difference between Inheritance & Polymorphism
Inheritance
polymorphism.pdf
OOP interview questions & answers.
What is Closure and Its Uses in PHP
Lecture6.ppt
JavaHTP6e_10.ppt
Php oop (1)
14_inheritance.ppt
Object Oriented Programming With Real-World Scenario
The smartpath information systems c plus plus

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Computing-Curriculum for Schools in Ghana
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Classroom Observation Tools for Teachers
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Trump Administration's workforce development strategy
PPTX
Cell Types and Its function , kingdom of life
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Anesthesia in Laparoscopic Surgery in India
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Computing-Curriculum for Schools in Ghana
Supply Chain Operations Speaking Notes -ICLT Program
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Classroom Observation Tools for Teachers
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Yogi Goddess Pres Conference Studio Updates
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Trump Administration's workforce development strategy
Cell Types and Its function , kingdom of life
History, Philosophy and sociology of education (1).pptx
Microbial disease of the cardiovascular and lymphatic systems

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