🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Immutability and Value Objects: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does this print? (code)
  2. Q2. A class has only private final List<String items; and no setters. Why can it still be mutable?
  3. Q3. Which line correctly makes a defensive, unmodifiable copy of a list parameter?
  4. Q4. Why is it important to override hashCode whenever you override equals?
  5. Q5. What does this print? (code)
  6. Q6. Which is the best example of a value object?
  7. Q7. Why are immutable objects automatically thread-safe?
  8. Q8. What does this print? (code)
  9. Q9. Where should validation for a record such as Money(long paise) go?
  10. Q10. Why is the class in an immutable design usually declared final?