ควิซ Java: Autoboxing & Wrapper Classes

This hard Java quiz is about wrapper classes like Integer and Long and the automatic boxing between them and primitives. It covers the classic interview gotchas: the Integer cache from -128 to 127, NullPointerException from unboxing, equals() across types and List.remove() with ints.

ยาก 10 ข้อ ~8 นาที ผ่านที่ 80% Java 17

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 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));
    }
}
ดูเฉลย

B. true false Autoboxing calls Integer.valueOf(), which returns cached objects for -128 to 127, so a and b are the same object. 128 is outside the cache, so c and d are different objects and == is false.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • The Integer cache and == on wrappers
  • Unboxing null and the ternary trap
  • equals() between Long and Integer
  • list.remove(int) vs list.remove(Object)
  • Wrapper keys in maps

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง