lesson 14 OOP .pdf - Lesson 14 Polymorphism 14.1...

This preview shows page 1 - 3 out of 6 pages.

Lesson 14: Polymorphism 14.1. Introduction In our previous lesson, we learnt about one of the features of OOP called inheritance- definition of inheritance, base class and derived class, data members and member functions, classification of member functions, types of inheritance and finally advantages and disadvantages of inheritance. Today, we will learn about another feature of OOP called polymorphism. 14.2. Lesson objectives By the end of this lesson you will be able to: Define polymorphism Describe virtual functions Describe different types of polymorphism Write simple program to demonstrate polymorphism. 14.3. Lesson outline This lesson is organized as follows: 14.1. Introduction 14.2. Lesson objectives 14.3. Lesson outline 14.4. Definition of polymorphism 14.5. Static polymorphism 14.6. Dynamic polymorphism 14.7. Virtual function 14.8. Revision questions 14.9. Summary 14.10. Suggested reading 14.4. Definition of polymorphism Polymorphism is a feature of OOP that allows programmers to create two functions with identical names. In essence, polymorphism means that some code or operation or object behaves differently in different contexts. In c++ polymorphism refers to using virtual functions. There are two types of polymorphism- static polymorphism and dynamic polymorphism. a) Subtype polymorphism : It's the ability to use derived classes through base class pointers and references .It is also known as runtime polymorphism . The resolution of polymorphic function calls happens at runtime through an indirection . Also called inclusion polymorphism. b) Parametric polymorphism : This is also known as compile-time polymorphism . This Polymorphism provides a means for executing the same code for any type. Can be implemented using templates or overriding or late binding . c) Ad-hoc polymorphism : This allows functions with the same name act differently for each type. It is also known as overloading or early binding.
d) Coercion polymorphism: This is also known as (implicit or explicit)

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture