🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.final classes run faster
  2. B.So its fields become final automatically
  3. C.So it can be used as a HashMap key at all
  4. 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 →