What is the main advantages of polymorphism | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is the main advantages of polymorphism

Polymorphism in Java and c#

25th Jun 2019, 10:29 AM
Muritala Muyideen Babatunde
Muritala Muyideen Babatunde - avatar
4 Answers
+ 5
It allows your objects to perform different actions depending on what object you call. For example, if a Vehicle class had a honk() method, and the classes Car and Truck extended it, then both would have a different implementation of a honk(a car would say something like “beep beep”, a truck “hooooooonk”, etc). It allows us to use the same method call for objects of different types(with the same superclass of course) without creating a new method name for each
25th Jun 2019, 10:52 AM
COLLIN PADGETT
COLLIN PADGETT - avatar
+ 3
Code reuse, scalability, effectiveness... Polymorphism makes manteinance easier, as you just need to edit once to make your changes, so it also fits the DRY. Search about DRY, SOLID, KISS...
25th Jun 2019, 10:54 AM
Alexander Santos
Alexander Santos - avatar
+ 1
During runtime polymorphism may lead to performance issue as machine need to decide which variable or method is to b selected
5th Oct 2019, 10:38 AM
Priya Trikoti
Priya Trikoti - avatar
0
The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. Real life example of polymorphism, a person at the same time can have different characteristic. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism. Polymorphism is considered as one of the important features of Object Oriented Programming. Advantage It helps programmers reuse the code and classes once written, tested and implemented. They can be reused in many ways. Single variable name can be used to store variables of multiple data types(Float, double, Long, Int etc). Polymorphism helps in reducing the coupling between different functionalities.
10th Oct 2019, 5:04 AM
Sunil kumar
Sunil kumar - avatar