SlideShare a Scribd company logo
POLYMORPISM
BY
IMTIAZ HUSSAIN
1
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;
 #include<iostream.h>
 #include<conio.h>
 class data
 {
 private:
 char name[12];
 int age;
 public:
 void input(){
 cout<<"Entr your name“;
cin>>name;
 cout<<"Enter your age"; cin>>age;}
 void show()
 {
 cout<<"Your name is "<<name;
 cout<<"Your age is "<<age;
 }
 };
 main()
 {
 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>
#include<conio.h>
class A
{
public:
void show() {
cout<<"This Is Base Class "<<endl; }
};
class B: public A
{
public:
void show() {
cout<<"This Is First Derived Class "<<endl; }
class C: public A{
public:
void show() {
cout<<"This Is Second Derived Class "<<endl; }
};
void main() {
A *ptr;
B C1;
C C2;
ptr=&C1;
ptr->show();
ptr=&C2;
ptr->show();
8
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
#include<iostream.h>
#include<conio.h>
class A
{
public:
virtual void show() {
cout<<"This Is Base Class "<<endl; }
};
class B: public A
{
public:
void show() {
cout<<"This Is First Derived Class "<<endl; }
};
class C: public A{
public:
void show() {
cout<<"This Is Second Derived Class "<<endl; }
};
void main() {
A *ptr;
B C1;
C C2;
ptr=&C1;
ptr->show();
ptr=&C2;
ptr->show();
getch(); }
11
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
THANKs
Good
Luck
15

More Related Content

Similar to polymorpisum-140106223024-phpapp01.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
CHAITALIUKE1
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Kumar Boro
 

Similar to polymorpisum-140106223024-phpapp01.pdf (20)

Polymorphism ppt
Polymorphism pptPolymorphism ppt
Polymorphism ppt
 
Polymorphism & inheritence ppt
Polymorphism & inheritence pptPolymorphism & inheritence ppt
Polymorphism & inheritence ppt
 
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
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.ppt
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Polymorphism and Virtual Functions ppt bioinformatics
Polymorphism and Virtual Functions ppt bioinformaticsPolymorphism and Virtual Functions ppt bioinformatics
Polymorphism and Virtual Functions ppt bioinformatics
 
Lecture6.ppt
Lecture6.pptLecture6.ppt
Lecture6.ppt
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
polymorphism.pdf
polymorphism.pdfpolymorphism.pdf
polymorphism.pdf
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 

More from BapanKar2

BAPANKAR15800121011 SOFT.pptx
BAPANKAR15800121011 SOFT.pptxBAPANKAR15800121011 SOFT.pptx
BAPANKAR15800121011 SOFT.pptx
BapanKar2
 
sameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptxsameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptx
BapanKar2
 
polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
BapanKar2
 
program-control-instruction.pdf
program-control-instruction.pdfprogram-control-instruction.pdf
program-control-instruction.pdf
BapanKar2
 
Chapter 6 - Program Control Instructions.pdf
Chapter 6 - Program Control Instructions.pdfChapter 6 - Program Control Instructions.pdf
Chapter 6 - Program Control Instructions.pdf
BapanKar2
 

More from BapanKar2 (9)

BAPANKAR15800121011 SOFT.pptx
BAPANKAR15800121011 SOFT.pptxBAPANKAR15800121011 SOFT.pptx
BAPANKAR15800121011 SOFT.pptx
 
osi-model.pptx
osi-model.pptxosi-model.pptx
osi-model.pptx
 
sameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptxsameermlr0parser-200701133032.pptx
sameermlr0parser-200701133032.pptx
 
set 5.pdf
set 5.pdfset 5.pdf
set 5.pdf
 
polymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdfpolymorphismpresentation-160825122725.pdf
polymorphismpresentation-160825122725.pdf
 
LR-Parsing.ppt
LR-Parsing.pptLR-Parsing.ppt
LR-Parsing.ppt
 
diodes.pdf
diodes.pdfdiodes.pdf
diodes.pdf
 
program-control-instruction.pdf
program-control-instruction.pdfprogram-control-instruction.pdf
program-control-instruction.pdf
 
Chapter 6 - Program Control Instructions.pdf
Chapter 6 - Program Control Instructions.pdfChapter 6 - Program Control Instructions.pdf
Chapter 6 - Program Control Instructions.pdf
 

Recently uploaded

Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
Kamal Acharya
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 

Recently uploaded (20)

NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
IT-601 Lecture Notes-UNIT-2.pdf Data Analysis
IT-601 Lecture Notes-UNIT-2.pdf Data AnalysisIT-601 Lecture Notes-UNIT-2.pdf Data Analysis
IT-601 Lecture Notes-UNIT-2.pdf Data Analysis
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docxThe Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
The Ultimate Guide to External Floating Roofs for Oil Storage Tanks.docx
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 

polymorpisum-140106223024-phpapp01.pdf

  • 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;  #include<iostream.h>  #include<conio.h>  class data  {  private:  char name[12];  int age;  public:  void input(){  cout<<"Entr your name“; cin>>name;  cout<<"Enter your age"; cin>>age;}  void show()  {  cout<<"Your name is "<<name;  cout<<"Your age is "<<age;  }  };  main()  {  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> #include<conio.h> class A { public: void show() { cout<<"This Is Base Class "<<endl; } }; class B: public A { public: void show() { cout<<"This Is First Derived Class "<<endl; } class C: public A{ public: void show() { cout<<"This Is Second Derived Class "<<endl; } }; void main() { A *ptr; B C1; C C2; ptr=&C1; ptr->show(); ptr=&C2; ptr->show(); 8
  • 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 #include<iostream.h> #include<conio.h> class A { public: virtual void show() { cout<<"This Is Base Class "<<endl; } }; class B: public A { public: void show() { cout<<"This Is First Derived Class "<<endl; } }; class C: public A{ public: void show() { cout<<"This Is Second Derived Class "<<endl; } }; void main() { A *ptr; B C1; C C2; ptr=&C1; ptr->show(); ptr=&C2; ptr->show(); getch(); } 11
  • 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