Skip to content
Sharp

Core Java · interview question

How would you correctly add two BigDecimal values representing product prices in Java?

Multiple choiceMediumchapter-1-curatedpremiumcore-javanumeric-types-and-money-basics
Choose one answer
Answer and explanation

Correct answer

D. Price1.add(price2)

Why

BigDecimal provides an add method to perform addition, ensuring precision in the operation. Using operators like '+' is not valid for BigDecimal.

Test yourself on Core Java

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

Start free test
All Core Java questions →