+ 5
What's is polymorphisme on OOP ?
Object Oriented Programming
6 Answers
+ 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");
}
}
+ 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.
+ 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.
+ 2
Thank you all about you answers :)
+ 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...