The following method accepts three arguments of type byte,int,int
and the method is called from another method which gives a compilation error that the method parameters are not applicable for int,int,int
.By default the byte parameter is not recognized until explicit casting is done.
public double subtractNumbers(byte arg1,int arg2,int arg3) {
double sum=arg1+arg2+arg3;
return sum;
}
Now method calling in another method as follows
public void call(){
subtractNumbers(15,16,17); /*Compile error,but 15 is in byte acceptable
range of -128 to 127 */
}
If i change the above calling as subtractNumbers((byte)15,16,17);
it works fine
When i declare a variable as byte c=15
it is accepted but when 15 is passed to a byte argument why there's a compile error;
int is the default literal for byte,short,int,long then why byte c=15 is accepted without casting but not method argument.
Thank you in advance.