CS FundamentalsHardProduct-company placement

Assertion (A): Classes that call a Singleton through its global getInstance() are harder to unit-test. Reason (R): The dependency is hidden inside the code rather than passed in, so a test cannot easily substitute a fake.

  1. A. Both A and R are true and R explains A
  2. B. Both A and R are true, but R does not explain A
  3. C. A is true but R is false
  4. D. A is false but R is true

Correct answer: A. Both A and R are true and R explains A

A hard-wired global lookup acts like hidden global state; tests share it and cannot inject a test double without extra hooks. Passing the instance in (dependency injection) fixes testability while keeping a single instance.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic