← All topics
Quiz: SOLID Principles: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. Which principle says "a class should have only one reason to change"?
- Q2. Adding a new payment type by writing a new class, without editing existing code, follows:
- Q3. A Square subclass that breaks code written for Rectangle violates:
- Q4. Passing a database object into a service's constructor instead of creating it inside is an example of:
- Q5. A fat interface forcing classes to implement methods they don't need violates:
- Q6. What is the difference between Dependency Inversion and Dependency Injection?
- Q7. What does this print? (code)
- Q8. A subclass overrides an inherited method only to throw "operation not supported". Which principle is likely violated?
- Q9. Why does OrderService that creates new MySQLDatabase() inside itself make testing hard?
- Q10. A basic printer class is forced to implement scan() and fax() with errors. What is the fix?