Skip to content
Sharp

Modern Java · interview question

Which of the following is a valid definition of a record in Java?

Multiple choiceMediumchapter-7-curatedpremiummodern-javarecords
Choose one answer
Answer and explanation

Correct answer

A. Record Product(String name, BigDecimal price) {}

Why

The correct syntax for defining a record in Java involves using the 'record' keyword followed by the record name and a parameter list encapsulated in parentheses. This syntax automatically generates necessary methods.

Test yourself on Modern Java

A free test with instant, explained results. No account needed.

Start free test
All Modern Java questions →