SlideShare une entreprise Scribd logo
1  sur  15
Dynamic Polymorphism

Objectives
In this lesson, you will learn to:
 Implement the concept of binding
 Use virtual functions
 Use pure virtual functions to create abstract classes
 Implement dynamic polymorphism by using late
  binding




©NIIT                                OOPS/Lesson 10/Slide 1 of 15
Dynamic Polymorphism

Dynamic Polymorphism
 Refers to any entity changing its form, depending on
  circumstances




©NIIT                               OOPS/Lesson 10/Slide 2 of 15
Dynamic Polymorphism

Binding
 Is the process of associating a function with a class by
  identifying the type of the object or pointer that is used
  to invoke the function




©NIIT                                 OOPS/Lesson 10/Slide 3 of 15
Dynamic Polymorphism

Binding (Contd.)
Example:


                               calc_net_salary()




                                 Employee class




           calc_net_salary()                       calc_net_salary()



              Trainee Class                          Confirmed Class




©NIIT                                                        OOPS/Lesson 10/Slide 4 of 15
Dynamic Polymorphism

Dynamic Binding
 Is done during runtime
 Is also called late binding




©NIIT                           OOPS/Lesson 10/Slide 5 of 15
Dynamic Polymorphism

Virtual Function
 Is a function that is declared as virtual in a base class
  and is redefined by a derived class




©NIIT                                 OOPS/Lesson 10/Slide 6 of 15
Dynamic Polymorphism

Using Virtual Functions
    Example:
    class Employee
    {
    .
    .
    virtual int calc_net_salary();
    .
    .
    };
    class Contract:public Employee
    {
    .
    .

©NIIT                       OOPS/Lesson 10/Slide 7 of 15
Dynamic Polymorphism

Using Virtual Functions (Contd.)
    int calc_net_salary();
    .
    .
    .
    };
    class Direct_Contract: public Contract
    {
    .
    .
    int calc_net_salary();
    .
    .
    };
©NIIT                          OOPS/Lesson 10/Slide 8 of 15
Dynamic Polymorphism

Pure Virtual Function
 Is a function without a body
 Is created by adding the notation ‘=0’ to the virtual
  function declaration
  Example:
  virtual int calc_net_salary()=0;




©NIIT                                 OOPS/Lesson 10/Slide 9 of 15
Dynamic Polymorphism

Abstract Class
 Is a class containing one or more pure virtual
  functions
 Is used as a base class for deriving specific classes of
  the same kind




©NIIT                               OOPS/Lesson 10/Slide 10 of 15
Dynamic Polymorphism

Static vs Dynamic Polymorphism
 Static polymorphism
     Is considered more efficient
     Is function overloading, which is bound by scopes -
      local and class scope




©NIIT                                OOPS/Lesson 10/Slide 11 of 15
Dynamic Polymorphism

Static vs Dynamic Polymorphism (Contd.)
 Dynamic polymorphism
     Is considered more flexible
     Is based on overriding principles, which, therefore,
      is purely class scope and is based on inheritance




©NIIT                                OOPS/Lesson 10/Slide 12 of 15
Dynamic Polymorphism

Problem Statement 8.D.1
Create an application that:
 Accepts customer details
 Accepts dealer details
 Displays customer details
 Displays dealer details




©NIIT                         OOPS/Lesson 10/Slide 13 of 15
Dynamic Polymorphism

Summary
In this lesson, you learned that:
 The instances of an abstract class cannot be created
  but pointers to it can be created
 A function exhibits dynamic polymorphism when it
  exists in more than one form, and calls to its various
  forms are resolved dynamically when the program is
  executed
 Static binding is considered to be more efficient while
  dynamic binding is more flexible




©NIIT                               OOPS/Lesson 10/Slide 14 of 15
Dynamic Polymorphism

Summary (Contd.)
 Dynamic polymorphism refers to an entity changing its
  form, depending on circumstances
 The virtual keyword is used to declare a function as
  virtual
 Virtual functions that have no body are called pure
  virtual functions
 A class containing one or more pure virtual functions
  is called an abstract class




©NIIT                               OOPS/Lesson 10/Slide 15 of 15

Contenu connexe

Similaire à Aae oop xp_10

Aae oop xp_08
Aae oop xp_08Aae oop xp_08
Aae oop xp_08Niit Care
 
Aae oop xp_03
Aae oop xp_03Aae oop xp_03
Aae oop xp_03Niit Care
 
Aae oop xp_09
Aae oop xp_09Aae oop xp_09
Aae oop xp_09Niit Care
 
polymorphism OOP.pptx
polymorphism OOP.pptxpolymorphism OOP.pptx
polymorphism OOP.pptxAssadLeo1
 
Vb net xp_14
Vb net xp_14Vb net xp_14
Vb net xp_14Niit Care
 
Introducing java oop concepts
Introducing java oop conceptsIntroducing java oop concepts
Introducing java oop conceptsIvelin Yanev
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioDurgesh Singh
 
Service oriented component model
Service oriented component modelService oriented component model
Service oriented component modelravindrareddy
 
Learn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingLearn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingEng Teong Cheah
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxkristinatemen
 
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)Matthias Noback
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My LifeMatthias Noback
 
9 crucial Java Design Principles you cannot miss
9 crucial Java Design Principles you cannot miss9 crucial Java Design Principles you cannot miss
9 crucial Java Design Principles you cannot missMark Papis
 

Similaire à Aae oop xp_10 (19)

Aae oop xp_08
Aae oop xp_08Aae oop xp_08
Aae oop xp_08
 
Aae oop xp_03
Aae oop xp_03Aae oop xp_03
Aae oop xp_03
 
Aae oop xp_09
Aae oop xp_09Aae oop xp_09
Aae oop xp_09
 
polymorphism OOP.pptx
polymorphism OOP.pptxpolymorphism OOP.pptx
polymorphism OOP.pptx
 
Lecture6.ppt
Lecture6.pptLecture6.ppt
Lecture6.ppt
 
Vb net xp_14
Vb net xp_14Vb net xp_14
Vb net xp_14
 
Introducing java oop concepts
Introducing java oop conceptsIntroducing java oop concepts
Introducing java oop concepts
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World Scenario
 
Service oriented component model
Service oriented component modelService oriented component model
Service oriented component model
 
Learn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator OverloadingLearn C# Programming Polymorphism & Operator Overloading
Learn C# Programming Polymorphism & Operator Overloading
 
Lecture11
Lecture11Lecture11
Lecture11
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
Virtual Functions
Virtual FunctionsVirtual Functions
Virtual Functions
 
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
9 crucial Java Design Principles you cannot miss
9 crucial Java Design Principles you cannot miss9 crucial Java Design Principles you cannot miss
9 crucial Java Design Principles you cannot miss
 
Ppt lesson 10
Ppt lesson 10Ppt lesson 10
Ppt lesson 10
 
Guice
GuiceGuice
Guice
 
Guice
GuiceGuice
Guice
 

Plus de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Dernier

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Aae oop xp_10

  • 1. Dynamic Polymorphism Objectives In this lesson, you will learn to: Implement the concept of binding Use virtual functions Use pure virtual functions to create abstract classes Implement dynamic polymorphism by using late binding ©NIIT OOPS/Lesson 10/Slide 1 of 15
  • 2. Dynamic Polymorphism Dynamic Polymorphism Refers to any entity changing its form, depending on circumstances ©NIIT OOPS/Lesson 10/Slide 2 of 15
  • 3. Dynamic Polymorphism Binding Is the process of associating a function with a class by identifying the type of the object or pointer that is used to invoke the function ©NIIT OOPS/Lesson 10/Slide 3 of 15
  • 4. Dynamic Polymorphism Binding (Contd.) Example: calc_net_salary() Employee class calc_net_salary() calc_net_salary() Trainee Class Confirmed Class ©NIIT OOPS/Lesson 10/Slide 4 of 15
  • 5. Dynamic Polymorphism Dynamic Binding Is done during runtime Is also called late binding ©NIIT OOPS/Lesson 10/Slide 5 of 15
  • 6. Dynamic Polymorphism Virtual Function Is a function that is declared as virtual in a base class and is redefined by a derived class ©NIIT OOPS/Lesson 10/Slide 6 of 15
  • 7. Dynamic Polymorphism Using Virtual Functions Example: class Employee { . . virtual int calc_net_salary(); . . }; class Contract:public Employee { . . ©NIIT OOPS/Lesson 10/Slide 7 of 15
  • 8. Dynamic Polymorphism Using Virtual Functions (Contd.) int calc_net_salary(); . . . }; class Direct_Contract: public Contract { . . int calc_net_salary(); . . }; ©NIIT OOPS/Lesson 10/Slide 8 of 15
  • 9. Dynamic Polymorphism Pure Virtual Function Is a function without a body Is created by adding the notation ‘=0’ to the virtual function declaration Example: virtual int calc_net_salary()=0; ©NIIT OOPS/Lesson 10/Slide 9 of 15
  • 10. Dynamic Polymorphism Abstract Class Is a class containing one or more pure virtual functions Is used as a base class for deriving specific classes of the same kind ©NIIT OOPS/Lesson 10/Slide 10 of 15
  • 11. Dynamic Polymorphism Static vs Dynamic Polymorphism Static polymorphism Is considered more efficient Is function overloading, which is bound by scopes - local and class scope ©NIIT OOPS/Lesson 10/Slide 11 of 15
  • 12. Dynamic Polymorphism Static vs Dynamic Polymorphism (Contd.) Dynamic polymorphism Is considered more flexible Is based on overriding principles, which, therefore, is purely class scope and is based on inheritance ©NIIT OOPS/Lesson 10/Slide 12 of 15
  • 13. Dynamic Polymorphism Problem Statement 8.D.1 Create an application that: Accepts customer details Accepts dealer details Displays customer details Displays dealer details ©NIIT OOPS/Lesson 10/Slide 13 of 15
  • 14. Dynamic Polymorphism Summary In this lesson, you learned that: The instances of an abstract class cannot be created but pointers to it can be created A function exhibits dynamic polymorphism when it exists in more than one form, and calls to its various forms are resolved dynamically when the program is executed Static binding is considered to be more efficient while dynamic binding is more flexible ©NIIT OOPS/Lesson 10/Slide 14 of 15
  • 15. Dynamic Polymorphism Summary (Contd.) Dynamic polymorphism refers to an entity changing its form, depending on circumstances The virtual keyword is used to declare a function as virtual Virtual functions that have no body are called pure virtual functions A class containing one or more pure virtual functions is called an abstract class ©NIIT OOPS/Lesson 10/Slide 15 of 15