Type casting into byte in Java
问题 I am a beginner in Java. I came across a concept called Type Casting. I have the following snippet- class Demo { byte b; int a=257; double d= 323.142 b=(byte)a; System.out.println(b); b=(byte)d; System.out.println(b); } The output for the code is- 1 67 Can anybody explain me the outputs. Thanks in Advance! 回答1: The byte type is encoded on 8 bits, so it takes its values between -128 and 127. In your case, casting by byte is the same as computing a modulo and rounding to an int . Try the