The word Polymorphism is formed from two words – poly and morph where poly means many and morph means forms. So polymorphism is the ability to use an operator or function in various forms. That is a single function or an operator behaves differently depending upon the data provided to them.
Polymorphism can be achieved in two ways:
1. Operator Overloading In class XI you have worked with ‘+ ‘operator. You must have noticed that the ‘+’ operator behaves differently with different data types. With integers it adds the two numbers and with strings it concatenates or joins two strings. For example:
Print 8+9 will give 17 and Print “Python” + “programming” will give the output as Pythonprogramming. This feature where an operator can be used in different forms is known as Operator Overloading and is one of the methods to implement polymorphism.
2. Function Overloading
Polymorphism in case of functions is a bit different. A named function can also vary depending on the
parameters it is given.