What will be indicated at the console as a result of the code:

public class B {
    public static void main(String[] args) {
        byte b = 127;
        byte result = (byte)(b + 1);
Variables of the byte type occupy 8 bits, 127 coded as 01111111 (0 - sign bit) after adding 1 we obtain the number encoded as 10000000 - which corresponds to -128
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback