0
OOPS
What is difference between polymorphism and overloading
4 Réponses
+ 1
Polymorphism means to have a same method with different implementations.
class Animal
{
public void sound(){}
}
class Dog extends Animal
{
public void sound() {
System.out.println("Woof");
}
}
overloading means to have the same method name but different parameter.
int sum (int a, int b)
{
return a + b;
}
int sum (int a, int b, int c)
{
return a + b + c;
}
double sum (double a, double b)
{
return a + b;
}
+ 1
Function overloading is a way to implement polymorphism to implement in Java
+ 1
So far I understand
Function overloading mean same function is accepting different number of parameters
While
Polymorphism mean different forms at the different places.
As here we all are Sololearner but here after we are student/teacher/programmer/many to name
0
Overloading is one of the concepts of polymorphism
Polymorphism = Overloading + Overriding
Overloading - Method name is same but there is a change in
No of parameters
Order of parameters
Size of parameters
We can overload method and constructor
Overriding : Method is same but implementation will be in subclass
If child class is not satisfied with the definition given by parent class
Child class will write its own definition
We can override instance method in all cases
We can override static method until and unless it is not having super keyword
We cannot override final method
We cannot override a constructor
Note : polymorphism can be implemented fully with the support of inheritance
If there is no inheritance there is no polymorphism