In fun(7) , 7 is an integer literal.
Try the following:
fun((byte)7);
Now comes to your question:
In case 1, byte b = 7; and System.out.println(b); are in the same area. Since 7 is suitable for byte , there is no need for explicit casting, and println(b) just discards the byte into string and prints 7 .
But in In case 2 they do not match. You call fun with Integer 7 from one area, where the called function in another area takes instead of byte int . Therefore, it does not matter whether 7 is suitable in byte or not, therefore, a compiler build error (request for explicit casting) before executing the System.out.println(b); program System.out.println(b); .
source share