Solving these questions will be easier, once you understand the fact that
1) byte is 8 bits long and hence the range is -128 to +127 (0 is on positive side).
2) Similarly int is 32 bits long and hence the range is -65536 to 65535
3) When an int literal is out of range for byte, looping occurs in the way that
-128 - 1 = 127
-128 - 2 = 126
+127 + 1 = -128
+127 + 2 = -127
Same applies for all primitive data type castings.
Sunny Bhandari wrote:Solving these questions will be easier, once you understand the fact that
1) byte is 8 bits long and hence the range is -128 to +127 (0 is on positive side).
2) Similarly int is 16 bits long and hence the range is -65536 to 65535
3) When an int literal is out of range for byte, looping occurs in the way that
-128 - 1 = 127
-128 - 2 = 126
+127 + 1 = -128
+127 + 2 = -127
Same applies for all primitive data type castings.
Hope that makes it crystal clear.
Just to making a little correction int is 32 bit log or say 4 byte .