Over loading means having the same method name but different type and order of parameters.
Overloading can not be done based only on return types.
class OverLoad1
{
void met1()
{
System.out.println("A");
}
int met1()
{
System.out.println("B");
return 10;
}
public static void main(String args[])
{
OverLoad1 o = new OverLoad1();
o.met1();
}
}
OUTPUT : Compile Error – met1() is already defined in OverLoad1
class OverLoad2
{
void met1(int a)
{
System.out.println("A");
}
int met1(String s)
{
System.out.println("B");
return 0;
}
public static void main(String args[])
{
OverLoad2 o = new OverLoad2();
o.met1(10);
}
}
OUTPUT : A