public static void main(String[] args) {
methodA(5);
}
public static void methodA(int i) {
System.out.println("int method " + i);
}
public static void methodA(short s) {
System.out.println("short method " + s);
}
The output of the above java program is
int method 5
So, when passing 5 as an argument, why method with int argument is called instead of short.
After casting the argument to short, the method with a short argument will be called.
methodA((short)5);
When I pass 5, why java considers it as int, whereas, for short I have to cast it? Considering, for short datatype, number range is -32,768 to 32767.