Skip to content
Sharp

Modern Java · interview question

In which scenario is a static factory method preferred over a constructor?

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

Correct answer

A. When returning a cached instance is desired.

Why

Static factory methods allow for returning cached instances, which can be beneficial for performance and memory efficiency. Constructors cannot perform this optimization.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →