🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Records and Sealed Classes: all 10 questions

Quiz: Records and Sealed Classes · Question 5 of 10

What is a compact constructor in a record used for?

What is a compact constructor in a record used for?

  1. A.Making the record smaller in memory
  2. B.Removing the generated toString
  3. C.Validating or adjusting the parameters before the fields are assigned
  4. D.Adding new instance fields
Answer & explanation

Correct answer: Validating or adjusting the parameters before the fields are assigned

Its code runs first; then the (possibly adjusted) parameters are assigned to the fields automatically.

Can you get the rest right without peeking?

Take the timed Quiz: Records and Sealed Classes quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →