Skip to content
Sharp

Spring Core · interview question

Why might constructor injection be preferred over setter injection in Spring?

Multiple choiceHardchapter-9-curatedpremiumspring-corebean-scope
Choose one answer
Answer and explanation

Correct answer

A. It makes beans immutable

Why

Constructor injection is preferred because it allows for immutable objects, ensuring that dependencies are set at creation time and cannot be changed later. This can lead to more robust and maintainable code.

Test yourself on Spring Core

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

Start free test
All Spring Core questions →