Skip to content
Sharp

Core Java · interview question

Given a record Product(String name, BigDecimal price), what is a potential issue with setting the price inappropriately?

Multiple choiceMediumchapter-7-curatedpremiumcore-javacode-reading-with-modern-java
Choose one answer
Answer and explanation

Correct answer

D. Using a null value for price will throw an exception at runtime.

Why

Records do not automatically handle null checks, so if a null value is passed for a field like price, it will not be caught until runtime, potentially causing a NullPointerException.

Test yourself on Core Java

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

Start free test
All Core Java questions →