value of byte range from -128 to 127 so 11 is not considered an int but if you go out of this range you will have to cast explicitly.
or if you had done something like this the also you need expliciti cast:
a + 20 results in an int so you need an explicit cast.
actually 12+14 is a compile time constant...so the compile puts the cast for you....but a+20 is not a compile time constant....the value of a is determined at runtime....the compile doesnt put a cast there..that is why 12+14 ran and a+20 didnt
scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Joined: Jan 04, 2010
I read that whole numbers are by default treated as integer in Java. So
byte i = 2;
will mean 2 as integer is being put in a byte after implicit typecasting.
Is this right?
Joined: Oct 30, 2009
yup, as raju said these are compile time constants and have implicit cast.