Skip to content
Sharp

Dependency Injection · interview question

Why is constructor injection preferred over field injection in terms of immutability?

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

Correct answer

D. Constructor injection makes dependencies immutable

Why

Constructor injection allows dependencies to be marked as 'final,' which ensures that they are set once and cannot be changed, thereby providing immutability. Field injection does not support this immutability feature as easily.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →