What is polymorphism explain it. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 8

What is polymorphism explain it.

do it occur in any other language also

13th Apr 2017, 9:51 AM
arpit dixit
arpit dixit - avatar
3 Respuestas
+ 15
The name suggests poly=many and morphisms=forms One thing with many forms is polymorphism. Like a Dettol Soap with varying sizes and colors. In programming, Suppose you want to add two numbers of datatype int, double, float but to make it possible you have to create 3 different functions with different names. With Polymorphism, you can achieve this with 3 functions with same name but different prototype ( means different argument type and numbers)
13th Apr 2017, 10:08 AM
Sachin Artani
Sachin Artani - avatar
+ 17
Polymorphism requirements: ‚ÄĘ you need to have classes with an IS-A relationship. ‚ÄĘ the classes need to have methods that are overridden. With the right initialisation and instantiation a call of the overridden method of the different objects will result in that the implemented method of the object belonging to a certain class will be executed. for example: overridden method = useSololearn(); call of this method in object A results in : "follow a Java course". for object B the result is : "follow a Python course". Polymorphism : ‚ÄĘ 1 overridden method call = useSololearn (); // (means same name and same argument list) ‚ÄĘ many forms = different implementations and code execution: "follow Java course" or "follow Python course". The great thing about this is that Java or another language is automatically going to decide on runtime (!) which code is going to be executed. ūüėł PS: Polymorphism is not going to work with same name plus different prototype.
4th May 2017, 5:30 AM
NimWing Yuan
NimWing Yuan - avatar
+ 1
Polymorphism is a OOPs concept where one name can have many forms. For example, you have a smartphone for communication. The communication mode you choose could be anything. It can be a call, a text message, a picture message, mail, etc. So, the goal is common that is communication, but their approach is different. This is called Polymorphism.
23rd Jun 2018, 8:39 PM
Pravin Yadav
Pravin Yadav - avatar