vaishnavi
03-17-2009, 02:33 AM
Hi all,
I have a doubt regarding function overloading. I have three functions which has arguments as short, int and long. A function call to short, calls the method with the int argument. why does it happen?
public class longshort
{
public static void go(Long n){System.out.println("Long ");}
public static void go(Short n){System.out.println("Short ");}
public static void go(int n){System.out.println("int ");}
public static void main(String args[])
{
short y=6;
long z=7;
go(y);
go(z);
}
}
The output of this code is:
int Long
Can anyone please explain me?
I have a doubt regarding function overloading. I have three functions which has arguments as short, int and long. A function call to short, calls the method with the int argument. why does it happen?
public class longshort
{
public static void go(Long n){System.out.println("Long ");}
public static void go(Short n){System.out.println("Short ");}
public static void go(int n){System.out.println("int ");}
public static void main(String args[])
{
short y=6;
long z=7;
go(y);
go(z);
}
}
The output of this code is:
int Long
Can anyone please explain me?