Opening Hours :7AM to 9PM
When ever same behavoiur is existing multiple times with separate implementation is known as PolyMorphism.
The main advantage with PolyMorphism is reusability.(both code reusability and object reusability).
because of code reusability burden of the developer will be reduced and code readability will be increased.
as per as java language is concent if the same method name existing multiple times with different signature with different implementation is known as PolyMorphism.
In java language these PolyMorphisms are classified into following types
1.Static PolyMorphism
2.Dynamic PolyMorphism
class Demo
{
void show()
{
System.out.println("hi");
}
void show()
{
System.out.println("welcome");
}
void show()
{
System.out.println("java");
}
}
class Main
{
public static void main(String args[])
{
Demo d=new Demo();
d.show();
}
}
Error:
method show already existing in the Demo class.
Note:
But Here PolyMorphism means same method name existing multiple times.But here if you take same method name multiple error will displayed.To overcome this problems overloading and overridding are introduced.
class Demo
{
Demo()
{
System.out.println("hi");
}
Demo(int x)
{
System.out.println("welcome");
}
Demo(int x,int y)
{
System.out.println("java");
}
}
class Main
{
public static void main(String args[])
{
Demo d=new Demo();
Demo d=new Demo(10);
Demo d=new Demo(10,20);
}
}