← Quiz: Immutability and Value Objects: all 10 questions
Quiz: Immutability and Value Objects · Question 10 of 10
Why is the class in an immutable design usually declared final?
Why is the class in an immutable design usually declared final?
- A.final classes run faster
- B.So its fields become final automatically
- C.So it can be used as a HashMap key at all
- D.So no subclass can add methods or fields that change state
Answer & explanation
Correct answer: So no subclass can add methods or fields that change state
A mutable subclass could be passed where the immutable type is expected and break its guarantees.
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 →