Polymorphism – Feature of Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

polymorphism.Polymorphism – Characteristics of Object Oriented Programming (OOP)
Object Oriented Programming(OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Polymorphism
Polymorphism or the ability to appear in many forms, is one of the vital primary characteristics concepts of OOP. ‘Poly’ means ‘many’ and ‘morph’ means ‘form’. In reference to OOP, it is an ability of assigning different meanings to entities such as variable, methods or objects so that these can be made to exhibit more than one form. It provides the programmers with the flexibility of processing any object differently depending upon their data types. Using this concept, a programmer can redefine various methods of the classes derived from their base classes. Objects of different types can receive the same message and respond in different ways provided these objects have the same method definition (i.e interface). The calling objects, also sometimes known as the client, need not know what type of object it is calling, the only thing that it needs to know or ensure is that the called object has a method of a specific name with defined arguments. Polymorphism is more often than not applied to derived classes, where the methods of the parent class are replaced with those having different behaviours. It is the concepts like inheritance and polymorphism that together make OOP flexible and easy to extend.

There are two categories of polymorphisms; static or compile-time and dynamic or run-time. In static polymorphism, which form of the method (from among the various available forms) is to be called and executed is decided during the time of compilation, the example being ‘Method Overloading’. In method overloading, same method name having different parameters is used more than once in the same class. Which method is to be called and executed depends upon the parameters passed by the calling method and is decided during the compilation of the program. The dynamic polymorphism is applied in the form of method overriding which means there can exist two or more methods in a program which have the same signature (name; return type; type, number and order of arguments to be passed) having different implementation. In figure below, these two types of polymorphism are explained.

two different types of polymorphism

(Visited 264 times, 1 visits today)

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag :

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary