Polymorphism is a concept in object-oriented programming that allows objects to take on multiple forms. Specifically, this means that different objects can be treated as if they are the same type of object. This is particularly useful in situations where there are multiple, related classes within a program, as polymorphism enables objects of different classes to be manipulated in the same way. However, it is important to be comfortable with certain related concepts, such as inheritance and overloading, in order to fully understand and make use of polymorphism. This tutorial will provide an overview of polymorphism and its various applications.

OOPs Concepts - Polymorphism

  • The English meaning of the word polymorphism is - having many forms.
  • In reference of object oriented programming
    • Polymorphism is the capability of a single entity (like function, operator etc.) to take different forms 
  • All these forms perform different actions in different scenarios
  • The name of all these forms remain the same.
  • Polymorphism is of two types : 
    • compile time polymorphism
    • run time polymorphism
  • Polymorphism is generally implemented when several classes are related to each other through inheritance.
  • An Example of polymorphism in Python is the Addition operator  + :
    • The  operator when used with integers becomes an addition operator and is used to find sum of values.
    • The same operator when used with strings becomes concatenation operator and is used to concatenate strings.
  • The same operator takes different forms and performs different function as per the data type of the operands - hence this is an example of polymorphism.

Prev. Tutorial : What is Inheritance

Next Tutorial : OOPs in Python