In the context of Java, please explain what a \"polymorphic method\" is.
Polymorphism is a process of representing 'one form in many forms'.
It is not a programming concept but it is one of the principle.
Example 1 :
class A
{
void print(double d)
{
System.out.println("Inside Double");
}
void print(float f)
{
System.out.println("Inside Float");
}
}
class B
{
public static void main(String [ ] args)
{
A obj1 = new A();
obj1.print(10.0);
}
}
Output :
//save as : B.java
//compile as :javac B.java
//run as : java B
Inside Double
______________________
Example 2 :
class A
{
void print(double d)
{
System.out.println("Inside Double");
}
void print(float f)
{
System.out.println("Inside Float");
}
}
class B
{
public static void main(String [ ] args)
{
A obj1 = new A();
obj1.print(10.0f);
}
}
Output :
//save as : B.java
//compile as :javac B.java
//run as : java B
Inside Float
_______________________
Example 3 :
class A
{
void print(double d)
{
System.out.println("Inside Double");
}
void print(float f)
{
System.out.println("Inside Float");
}
}
class B
{
public static void main(String [ ] args)
{
A obj1 = new A();
obj1.print(10);
}
}
Output :
//save as : B.java
//compile as :javac B.java
//run as : java B
Inside Float
To know more - http://algovalley.com/java/polymorphism.php