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

Quiz: SOLID in Java · Question 5 of 10

Why is ResultService(ResultStore store, Notifier notifier) easier to test than a class that does new MySqlStore() insid…

Why is ResultService(ResultStore store, Notifier notifier) easier to test than a class that does new MySqlStore() inside?

  1. A.Constructors run faster than new
  2. B.Interfaces use less memory
  3. C.A test can pass an in-memory store and a fake notifier, so no real database or SMS gateway is needed
  4. D.MySQL cannot be used from Java tests
Answer & explanation

Correct answer: A test can pass an in-memory store and a fake notifier, so no real database or SMS gateway is needed

Injecting dependencies through the constructor lets tests choose lightweight replacements.

Can you get the rest right without peeking?

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

Start the quiz →