Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › OOP I — Classes, Objects, Constructors

Explain what a record is, what it generates, and where a record is the wrong choice.

Level II · JuniorOOP I — Classes, Objects, Constructors
Short answer

A record (Java 16) is a transparent carrier for immutable data: from the header it generates final fields, a canonical constructor, accessors, and value-based equals/hashCode/toString.

Explanation

It is ideal for DTOs, value objects, and multiple return values. It is the wrong choice when you need mutability, want to hide or transform internal representation, need inheritance (records are implicitly final and extend Record), or when equality should be identity-based rather than component-based.

Common mistakes
  • Using records for JPA entities that need mutability and a no-arg constructor.
  • Thinking records make referenced objects immutable too.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for OOP I — Classes, Objects, Constructors.

Practise free

More on OOP I — Classes, Objects, Constructors