Sankar,
The result of any expression which involves either an int-size or smaller always results into an
int. That implies they will be converted to an
int. So as of here when you are adding as
byte c= a+b;. The result of a+b gives an
int where as c is a
byte.So it will give a type mismatch error.
Whereas in second case where you are giving
byte c=2+5;.
The value of 2+5 is again an int but compiler automatically narrows down it into a byte by implicitly casting (This is true for any integer literal i.e any int value like 5,7,23...)
Thus
byte c= 2+5; is equivalent to
byte c= byte (2+5); This is true for char and short too as both are shorter than int, though here it was for byte
[ October 03, 2007: Message edited by: pranav bhatt ]