Skip to content
Sharp

Modern Java · interview question

In what way can static factory methods improve validation when creating instances of classes?

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

Correct answer

C. They can perform validation logic before returning an object.

Why

Static factory methods can include validation logic before an object is created, ensuring that only valid objects are instantiated and returned.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →