Your SlideShare is downloading. ×
0
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Aae oop xp_10
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Aae oop xp_10

359

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
359
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Dynamic PolymorphismObjectivesIn 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 PolymorphismDynamic Polymorphism Refers to any entity changing its form, depending on circumstances©NIIT OOPS/Lesson 10/Slide 2 of 15
  • 3. Dynamic PolymorphismBinding 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 PolymorphismBinding (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 PolymorphismDynamic Binding Is done during runtime Is also called late binding©NIIT OOPS/Lesson 10/Slide 5 of 15
  • 6. Dynamic PolymorphismVirtual 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 PolymorphismUsing Virtual Functions Example: class Employee { . . virtual int calc_net_salary(); . . }; class Contract:public Employee { . .©NIIT OOPS/Lesson 10/Slide 7 of 15
  • 8. Dynamic PolymorphismUsing 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 PolymorphismPure 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 PolymorphismAbstract 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 PolymorphismStatic 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 PolymorphismStatic 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 PolymorphismProblem Statement 8.D.1Create 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 PolymorphismSummaryIn 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 PolymorphismSummary (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

×