Skip to content
Sharp

Modern Java · interview question

Why might a developer choose a static factory method over a constructor when creating a BigDecimal instance?

Multiple choiceMediumchapter-7-curatedpremiummodern-javastatic-factory-methods
Choose one answer
Answer and explanation

Correct answer

B. To ensure correct scale of the BigDecimal.

Why

Static factory methods for BigDecimal, such as BigDecimal.valueOf, ensure that the scale and precision are set correctly, which is not always the case with constructors.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →