Skip to content
Sharp

Dependency Injection · interview question

Which of the following is a benefit of using 'final' with constructor-injected dependencies?

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

Correct answer

B. It ensures dependencies are immutable.

Why

Using 'final' with constructor-injected dependencies ensures that these dependencies are immutable after the object is constructed, which aligns with best practices for creating robust and maintainable code.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →