Skip to content
Sharp

Dependency Injection · interview question

Why is constructor injection preferred for mandatory dependencies?

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

Correct answer

C. It makes dependencies explicit and keeps the object valid at creation time

Why

Constructor injection shows what the class needs up front and makes direct unit testing easier. Hidden dependencies are harder to reason about and easier to misuse.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →