← Quiz: Immutability and Value Objects: all 10 questions
Quiz: Immutability and Value Objects · Question 2 of 10
A class has only private final List<String items; and no setters. Why can it still be mutable?
A class has only private final List<String> items; and no setters. Why can it still be mutable?
- A.final fields can be reassigned with reflection only
- B.The list object itself can be modified through any reference to it
- C.final has no effect on private fields
- D.Lists cannot be stored in final fields
Answer & explanation
Correct answer: The list object itself can be modified through any reference to it
final fixes the reference, not the contents of the list it points to.
Can you get the rest right without peeking?
Take the timed Quiz: Immutability and Value Objects quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →