Skip to content
Sharp

Modern Java · interview question

How would you explain a key benefit of using static factory methods when creating instances of immutable value objects in an interview?

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

Correct answer

D. They can return a subclass of their return type.

Why

Static factory methods can return a subclass of their return type, providing greater flexibility in the creation of instances, especially for immutable value objects.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →