Java Primitives & Variables Quiz

This Java quiz checks how well you know the eight primitive types and how variables behave. You will predict output involving overflow, char arithmetic, default values and var, and spot code that does not compile.

Easy 10 questions ~5 minutes Pass at 80% Java 17

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

public class Main {
    public static void main(String[] args) {
        int x = Integer.MAX_VALUE;
        x = x + 1;
        System.out.println(x);
    }
}
Show the answer

B. -2147483648 An int is 32 bits, so adding 1 to Integer.MAX_VALUE silently wraps around to Integer.MIN_VALUE. Java does not throw on integer overflow.

What this quiz covers

  • The primitive types and their fixed sizes
  • Integer overflow and long literals
  • char as a number and double precision
  • Default values of fields vs uninitialized local variables
  • Type inference with var

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.