Java-Quiz: Records, var & switch Expressions

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.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% Java 17

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 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);
    }
}
Lösung zeigen

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.

Darum geht es in diesem Quiz

  • 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

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.