What is dependency injection?
-
A pattern (design) whereby collaborators are passed into an object from the outside - the object does not allocate them for itself.
-
It is a pattern in which the child class inherit the parent class properties
-
It is a type of operator overloading in java
-
It represents the compile time and run time polymorphism in java
Dependency injection is a design pattern where objects receive their dependencies from external sources rather than creating them internally. This promotes loose coupling, easier testing, and better code maintainability by allowing dependencies to be swapped or mocked.
Dependency injection is a design pattern where an object's collaborators (dependencies) are supplied to it from the outside — typically via constructor, setter, or field injection — rather than the object creating or looking them up itself. This inverts control of dependency creation, making classes easier to test and decouple from concrete implementations. It's unrelated to inheritance, operator overloading, or polymorphism, which the distractors incorrectly claim.