Polymorphism in java

Polymorphism
The word ‘Polymorphism’ came from two greek words ‘poly’ meaning ‘many’ and ‘morphs’ meaning ‘forms’.Thus, polymorphism represent the ability to assume several different forms.

In java, when one task is performed by different ways is known as polymorphism. We use method overloading and method overriding to achieve polymorphism.

Example of polymorphism
class one
{
void cal(int x)
{
System.out.println(“Square is”+(x*x));
}
}
class two extends one
{
void cal(int x)
{
System.out.println(“Cube is”+(x*x*x));
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *