Which of these can a Java record class not declare in its body?
Correct answer A. An additional instance field
Explanation
A record's state is defined entirely by its header, so declaring any further instance field is a compile-time error. Static fields, instance methods and a compact canonical constructor, often used for validation, are all allowed. This restriction ensures that the generated equals, hashCode and toString methods describe the complete state of a record.
Answer checked How we write and check questions
Discussion