Skip to content
Sharp

Dependency Injection · interview question

Why is constructor injection generally preferred over field injection in Spring Boot applications?

Multiple choiceEasychapter-9-curatedpremiumdependency-injectionconstructor-vs-field-injection
Choose one answer
Answer and explanation

Correct answer

B. It promotes immutability and easier testing.

Why

Constructor injection allows for dependencies to be final, promoting immutability. It also makes testing easier as dependencies can be provided through the constructor rather than requiring reflection or access to private fields.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →