Practice mode Java

Which Java keyword declares a shallowly immutable data carrier class?

Correct answer A. record

Explanation

A record declaration, standard since Java 16, names its components in a header, and the compiler generates private final fields, a canonical constructor, accessors, equals, hashCode and toString. It is only shallowly immutable, because a component holding a mutable object can still be changed internally. The words data, struct and tuple are not Java class declarations.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.