+ 20
overloading is compile time polymorphism and overriding is runtime polymorphism
+ 8
POLYMORPHISM
POLY MEANS MANY
MORPHUS MEANS FORMS
POLYMORPHISM MEANS MANYFORMS
OR
SEEING THE SAME THING IN MANY WAYS IS CALLED POLYMORPHISM
THERE ARE TWO CONCEPTS
OVERLOADING
OVERRIDING
OVERLOADING : METHOD NAME IS SAME BUT
1 NO OF PARAMTERS
2 ORDER OF PARAMETERS
3 SIZE OF PARAMETERS
WILL BE DIFFERENT
EXAMPLE 1 (METHOD)
class Polygon
{
public void area(float r)
{
System.out.println(âArea = â + Math.PI*r*r);
}
public void area(int s)
{
System.out.println(âArea = â + s*s);
}
}
class Oltest
{
public static void main(String args[])
{
Polygon p=new Polygon();
p.area(2.25F);
p.area(10);
}
}
========================
EXAMPLE 2 (CONSTRUCTOR)
class Area
{
public Area(int l,int b)
{
System.out.println(âArea = â + l*b);
}
public Area(int s)
{
System.out.println(âArea = â + s*s);
}
}
class Contest
{
public static void main(String args[])
{
new Area(10,15);
new Area(10);
}
}
========================
OVERRIDING
METHOD IS SAME BUT IMPLEMENT IN ANOTHER CLASS
OVERRIDING IS REQUIRED IF CHILD CLASS IS NOT SATISTYING WITH THE DEFINITION GIVEN BY PARENT CLASS
SO CHILD WILL DEFINE ITS OWN CODE
THIS IS CALLED OVERRIDING
FOR OVERRIDING INHERITANCE IS NECESSARY
THATS WHY POLYMORPHISM WILL BE FULFILLED ONLY WITH INHERITANCE
EXAMPLE
class Square
{
public void calculate(int s)
{
System.out.println(âSquare = â + s*s);
}
}
class SqaureRoot extends Square
{
public void calculate(int s)
{
System.out.println(âSquareroot = â + Math.sqrt(s));
}
}
class Ortest
{
public static void main(String args[])
{
Squareroot s= new Squareroot();
s.calculate(100);
}
}
+ 4
Both are ways of achieving polymorphism... polymorphism means of many forms
See https://googleweblight.com/i?u=https://stackoverflow.com/questions/7489335/overriding-vs-polymorphism&hl=en-KE
+ 2
In Java, it is both.
The first one is the well known overloading while the other one is runtime polymorphism which is implemented using method overriding.
- 2
i dont know HaHaHAHaHa