English

Explain polymorphism with an example.

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?
Chapter 2: Concept of Object Oriented Programming - EXCERCISE [Page 37]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 2 Concept of Object Oriented Programming
EXCERCISE | Q 8. | Page 37
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×