Tricky Java Questions

This Java quiz collects the gotchas that trip up even experienced developers in interviews. Expect integer caching, hidden casts, silent overflow, unboxing surprises and a loop that should fail but does not.

Khó 10 câu hỏi ~8 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 {
    public static void main(String[] args) {
        Integer a = 127, b = 127;
        Integer c = 128, d = 128;
        System.out.println((a == b) + " " + (c == d));
    }
}
Xem đáp án

B. true false Autoboxing uses Integer.valueOf, which caches the values -128 to 127. a and b are the same cached object, while each 128 is a new object, so == compares two different references. Use equals().

Quiz này có gì

  • Integer caching and == on wrappers
  • Unboxing null in a ternary expression
  • Hidden casts in compound assignment and silent overflow
  • String constants, Math.abs and Double.MIN_VALUE
  • Removing from a list in a for-each loop, and the equals/hashCode contract

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.