Advertisements
Advertisements
Question
Explain polymorphism with an example.
Explain
Advertisements
Solution
Polymorphism means “many forms”. It is the ability of the same operator or function name to behave differently for different data or arguments.
Example — operator overloading: The + operator adds numbers but joins strings.
print(8 + 9) # Addition: 17
print("Python " + "Programming") # Concatenation: Python Programming
Thus, the same + operator performs different operations according to the type of operands.
shaalaa.com
Is there an error in this question or solution?
