What happens when I assign value larger than byte?
According to official oracle documentation, Byte is
Byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation
My code is
public class B
{
public static void main(String args[])
{
byte b;
b=(byte)129;
System.out.println("b="+b);
}
}
Output:
b=-127
What happens when I assign value larger than byte. Java compiler will report an error. I will go if I cast this value to byte
byte b = (byte) 128;
I do not understand the output of this program?