What restrictions are placed on method overloading?
Two methods may not have the same name and argument list but different return types.
MethodOverloadingDemo.java
class Method123
{
void meth()
{
System.out.println("No parameter method");
}
void meth(int n)
{
System.out.println("The value of n is:" +n);
}
void meth(int a, int b)
{
System.out.println("The value of a and b is" +a + " " +b);
}
double meth (double m)
{
System.out.println("The value of m is:" +m);
return (m*m);
}
}
class MethodOverloadingDemo
{
public static void main(String arg[])
{
Method123 d =new Method123();
double result;
d.meth();
d.meth(10);
d.meth(10,20);
result=d.meth(3.14);
System.out.println("The Result of d.Method(3.14) is:" +result);
}
}
Recent Comments