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