+ 8
What is polymorphism explain it.
do it occur in any other language also
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)
+ 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.
+ 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.