Skip to content
Sharp

Core Java · interview question

Consider a static factory method public static Order createOrder(String id, BigDecimal amount). What flexibility does this pattern provide over direct constructor calls?

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

Correct answer

A. It allows for control over the object creation process.

Why

Static factory methods allow for more flexibility in object creation, such as returning different subtypes, controlling the number of instances, or applying custom logic before returning the object.

Test yourself on Core Java

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

Start free test
All Core Java questions →