What will be printed if you compile and run the following code:

public class Quizful {
    public static void main(String[] args) {
        byte b = 127;
        b += 129;
        System.out.println(b);
    }
}
Explanation
Byte type range is: from -128 to 127, where 127 + 1 = -128.
There is no compilation error for += operation, while there would be a compile error for b = b + 129 as result of + would be 256 with int type.

Follow CodeGalaxy

Mobile Beta

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