Ba từ khóa không liên quan nhau dù tên giống — câu này kiểm tra độ nắm chắc khái niệm cơ bản.
final— modifier: biến không gán lại được, method không override được, class không kế thừa được (chi tiết xem câu keyword final).finally— block trong try/catch, luôn chạy dù có exception hayreturngiữa chừng → chỗ dọn resource (đóng file, connection). Từ Java 7, ưu tiên try-with-resources thay cho finally thủ công.finalize()— method củaObject, được GC gọi trước khi thu hồi object. Deprecated từ Java 9, đánh dấu xoá từ Java 18 (JEP 421) — không đảm bảo được gọi hay gọi lúc nào → dọn resource bằng try-with-resources hoặcjava.lang.ref.Cleaner.
Trả lời gọn khi phỏng vấn: 3 khái niệm ở 3 phạm trù khác nhau — modifier / control flow / GC hook (đã khai tử).
Three keywords that are completely unrelated despite similar names — this question tests how solid your fundamentals are.
final— a modifier: variables cannot be reassigned, methods cannot be overridden, classes cannot be extended (see the final keyword item).finally— a block in try/catch that always runs, even with exceptions or an earlyreturn→ the place to clean up resources (closing files, connections). Since Java 7, prefer try-with-resources over manual finally.finalize()— a method onObject, called by the GC before reclaiming the object. Deprecated since Java 9, marked for removal since Java 18 (JEP 421) — no guarantee it runs or when → clean up with try-with-resources orjava.lang.ref.Cleaner.
Concise interview answer: three concepts in three different realms — modifier / control flow / GC hook (now retired).