Java Records, var & switch Expressions Quiz

This Java quiz covers the features added between Java 10 and 17 that make everyday code shorter: records, var and switch expressions. You will predict output, find code that does not compile and compare the new switch with the classic one.

Medium 10 questions ~6 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 {
    record Point(int x, int y) {}

    public static void main(String[] args) {
        Point p = new Point(3, 4);
        System.out.println(p);
    }
}
Show the answer

B. Point[x=3, y=4] Records get a generated toString() in the form Name[field=value, ...] with square brackets. A normal class without toString() would print the class name and a hash.

What this quiz covers

  • What a record generates (constructor, accessors, equals, hashCode, toString)
  • Compact constructors for validation
  • Where var works and what type it infers
  • Arrow switch expressions, multiple labels and yield
  • Fall-through in the classic switch statement

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.