byte and short have no overflow checking. Incrementing past MAX_VALUE silently wraps to the type's minimum instead of throwing.
byte b = 127;
b++;
short s = 32767;
s++;
System.out.println("byte 127 + 1 = " + b);
System.out.println("short 32767 + 1 = " + s);
byte 127 + 1 = -128
short 32767 + 1 = -32768
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27