🎙 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 9 of 10

Where should validation for a record such as Money(long paise) go?

Where should validation for a record such as Money(long paise) go?

  1. A.In a setter method
  2. B.In a compact constructor inside the record
  3. C.In every method that uses the record
  4. D.Records cannot be validated
Answer & explanation

Correct answer: In a compact constructor inside the record

The compact constructor runs before fields are assigned, so invalid records cannot be created.

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 →