What's is polymorphisme on OOP ? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 5

What's is polymorphisme on OOP ?

Object Oriented Programming

1st Jul 2017, 6:37 AM
Chemseddine Zara
Chemseddine Zara - avatar
6 ответов
+ 3
In Java when we talk about polymorphism we talk about extending a class. The polymorphism is used to describe actions(methods) with different functionality, depending on the class. So if we have the class Animal and put there the method walk(). When extending the class Animal to the Monkey class, we have to give the walk() method a different implementation, and so on for the rest of the animals. EXAMPLE: class Animal(){ void walk(){ System.out.println("This is the base class, abstraction of walking, it will be overriden, so it does not matter what it is written here"); } } class Moneky extends Animal{ @Override void walk(){ System.out.println("" The monkey may walk on 4 or 2 limbs): } } class Fish(){ void walk(){ System.out.println("The fish does not walk, better structure is needed"); } }
1st Jul 2017, 7:13 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
+ 2
It is the fact that something can be use with more than one purpose. For example, overloading a constructor to be able to use either one or two parameters is a kind of polymorphism.
1st Jul 2017, 6:39 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
Making more constructors like Baptiste said is called Overloading. Overloaded method should always be the part of the same class (can also take place in sub class), with same name but different parameters. The parameters may differ in their type or number, or in both. They may have the same or different return types. It is also known as compile time polymorphism.
1st Jul 2017, 7:23 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
1st Jul 2017, 10:33 AM
Aibek T.
Aibek T. - avatar
+ 2
Thank you all about you answers :)
1st Jul 2017, 1:45 PM
Chemseddine Zara
Chemseddine Zara - avatar
+ 1
see, property of any piece of code to be able to process in more than one way is called polymorphism. example could be constructor overloading and function overloading hope you got it...
1st Jul 2017, 1:36 PM
DEVIL kingg
DEVIL kingg - avatar