In the above code compilation error is occuring at line 1. Says cant cast from int to byte. I know that byte values range from -128 to 127. Then why b1 value is not accepted as byte.what is the error? am i missing any point in casting.please explain.
It's because any arithmetic operations will atleast result in an integer.
Ex : - 1. byte + byte = int 2. int + byte = int 3. float + int = float
Also in this line b2 = b1 + 1
At run time there is a possibility that b1 is greater than 127, so it's greater than the size of byte & hence the compiler throws error. Explicit cast is required here. [ July 09, 2005: Message edited by: Srinivasa Raghavan ]