Skip to content
Sharp

Spring Core · interview question

Why is constructor injection preferred over field injection in Spring?

Multiple choiceMediumchapter-9-curatedpremiumspring-coreinversion-of-control-ioc
Choose one answer
Answer and explanation

Correct answer

A. It ensures all dependencies are immutable and available at creation time.

Why

Constructor injection is preferred because it ensures that all dependencies are provided upon object creation, making them immutable and easily testable. This approach also supports better encapsulation and facilitates easier testing by enforcing dependency availability.

Test yourself on Spring Core

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

Start free test
All Spring Core questions →