Skip to content
Sharp

Dependency Injection · interview question

What advantage does constructor injection offer over field injection concerning encapsulation?

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

Correct answer

B. Constructor injection enhances encapsulation by making dependencies explicit

Why

Constructor injection enhances encapsulation by making dependencies explicit in the class constructor, which clearly communicates the class's dependencies and responsibilities, unlike field injection where dependencies are hidden within the class.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →