🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: SOLID Principles: all 10 questions

Quiz: SOLID Principles · Question 4 of 10

Passing a database object into a service's constructor instead of creating it inside is an example of:

Passing a database object into a service's constructor instead of creating it inside is an example of:

  1. A.Inheritance
  2. B.Dependency injection (to follow Dependency Inversion)
  3. C.Interface segregation
  4. D.Encapsulation only
Answer & explanation

Correct answer: Dependency injection (to follow Dependency Inversion)

The service depends on an abstraction that is given to it.

Can you get the rest right without peeking?

Take the timed Quiz: SOLID Principles quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →