Loading…
Loading…
Ten exam-style questions on the immutability recipe, final fields that still leak, defensive copies in constructors and getters, List.copyOf versus unmodifiable views, arrays, and shallowly immutable records, with explanations.
Practice questions for the article Java Immutable Objects and Defensive Copies.
For each class, look for every path by which outside code could reach a mutable object inside it. Aim for at least 8 out of 10.
Quiz path: step 41. Take the quizzes in this order, after reading each article.
Previous quiz: Abstract Classes and Abstract Methods (OCP 21)
Next quiz: Chapter 6 Review: Class Design (OCP 21)
10 questions · pass at 68%
Check your understanding; you see the answers and explanations after submitting.
Discussion
Sign in to ask a question or share what you learned.