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

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes