Quiz Java: 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.

Trung bình 10 câu hỏi ~6 phút Đạt từ 80% Java 17

Chọn chế độ

Bạn đang chơi với tư cách khách: đăng nhập để lưu XP và streak.

Câu hỏi mẫu

Câu 1/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);
    }
}
Xem đáp án

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.

Quiz này có gì

  • 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

Câu hỏi thường gặp

Có cần tài khoản không?

Không. Ai cũng chơi được. Đăng nhập để lưu XP, streak, badge và lịch sử.

Có làm lại được không?

Được. Điểm cao nhất của bạn được giữ lại, câu hỏi và đáp án được xáo trộn mỗi lần.