SW-2 Lecture 4 MCQ (SOLID)
SW-2 Lecture 4 MCQ (SOLID)
1. Which SOLID principle suggests that a class should have only one reason to change?
a) Single Responsibility Principle (SRP)
b) Open/Closed Principle (OCP)
c) Liskov Substitution Principle (LSP)
d) Interface Segregation Principle (ISP)
e) Dependency Inversion Principle (DIP)
Correct answer: a) Single Responsibility Principle (SRP)
2. Which SOLID principle promotes the idea of adding new features without modifying
existing code?
a) SRP
b) OCP
c) LSP
d) ISP
e) DIP
Correct answer: b) Open/Closed Principle (OCP)
8. The Liskov Substitution Principle (LSP) is closely related to which programming concept?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Abstraction
Correct answer: c) Polymorphism
9. Which SOLID principle emphasizes creating smaller and more focused interfaces?
a) SRP
b) OCP
c) LSP
d) ISP
e) DIP
Correct answer: d) Interface Segregation Principle (ISP)
11. Which SOLID principle helps prevent coupling and ensures clients only depend on
12. The Single Responsibility Principle (SRP) promotes which of the following?
a) Classes with multiple responsibilities
b) Classes with no responsibilities
c) Classes with a single responsibility
d) Classes with responsibilities that frequently change
Correct answer: c) Classes with a single responsibility
13. The Open/Closed Principle (OCP) encourages software entities to be open for:
a) Modification
b) Extension
c) Both modification and extension
d) Neither modification nor extension
Correct answer: b) Extension
14. The Liskov Substitution Principle (LSP) is concerned with the relationship between:
a) Objects of the same class
b) Objects of different classes
c) Objects of the base class and its subclasses
d) Objects of the derived class and its base class
Correct answer: c) Objects of the base class and its subclasses
15. Which SOLID principle suggests using abstraction to decouple high-level and low-level
modules?
a) SRP
b) OCP
c) LSP
d) ISP
e) DIP
Correct answer: e) Dependency Inversion Principle (DIP)
17. The Single Responsibility Principle (SRP) aims to make classes easier to:
a) Understand, maintain, and test
b) Modify, extend, and reuse
c) Compile, execute, and optimize
d) Analyze, debug, and refactor
Correct answer: a) Understand, maintain, and test
18. The Open/Closed Principle (OCP) suggests that modifying existing code can lead to:
a) Easier debugging
b) Improved performance
c) Increased coupling
d) Code reusability
Correct answer: c) Increased coupling
19. Which SOLID principle ensures that objects of a subclass can be used interchangeably
with objects of its superclass?
a) SRP
b) OCP
c) LSP
d) ISP
e) DIP
Correct answer: c) Liskov Substitution Principle (LSP)
20. The Dependency Inversion Principle (DIP) promotes loose coupling by depending on:
a) Concrete implementations
b) High-level modules only
c) Low-level modules only
d) Abstractions
Correct answer: d) Abstractions
1. Which SOLID principle promotes adding new features without modifying existing code?
Answer: b) Open/Closed Principle (OCP)
2. Which SOLID principle focuses on objects being replaceable with their subtypes?
Answer: c) Liskov Substitution Principle (LSP)
3. Which SOLID principle emphasizes that clients should not be forced to depend on
unnecessary interfaces?
Answer: d) Interface Segregation Principle (ISP)
4. Which SOLID principle states that high-level modules should not depend on low-level
modules directly?
Answer: a) Dependency Inversion Principle (DIP)
Certainly! Here are 30 more multiple-choice questions (MCQs) related to the SOLID
principles, along with their correct answers:
1. Which SOLID principle emphasizes that a class should have only one reason to change?
Answer: a) Single Responsibility Principle (SRP)
2. Which SOLID principle states that software entities should be open for extension but
closed for modification?
Answer: b) Open/Closed Principle (OCP)
3. Which SOLID principle focuses on the behavior and contracts of the base class and its
derived classes?
Answer: c) Liskov Substitution Principle (LSP)
4. Which SOLID principle promotes the use of smaller and more focused interfaces?
Answer: d) Interface Segregation Principle (ISP)
5. Which SOLID principle suggests that high-level modules should not depend on low-level
modules directly, but both should depend on abstractions?
Answer: a) Dependency Inversion Principle (DIP)
6. Which SOLID principle helps in achieving flexibility, decoupling, and ease of testing?
Answer: a) Dependency Inversion Principle (DIP)
7. Which SOLID principle focuses on making it easier to reason about properties of the
system at the implementation level?
Answer: c) Liskov Substitution Principle (LSP)
8. Which SOLID principle states that a class or module should have a single responsibility or
job?
Answer: a) Single Responsibility Principle (SRP)
10. Which SOLID principle enables objects of a derived class to be substituted for objects of
a base class without affecting the correctness of the program?
Answer: c) Liskov Substitution Principle (LSP)
11. Which SOLID principle promotes adding new features by extending existing code rather
than modifying it?
Answer: b) Open/Closed Principle (OCP)
12. Which SOLID principle suggests creating modules that are independent of specific
implementations and depend on abstractions?
Answer: a) Dependency Inversion Principle (DIP)
13. Which SOLID principle focuses on designing smaller and more focused interfaces to
prevent clients from depending on unnecessary functionality?
Answer: d) Interface Segregation Principle (ISP)
14. Which SOLID principle helps in isolating changes and reducing the impact of
modifications?
Answer: b) Open/Closed Principle (OCP)
15. Which SOLID principle ensures that objects of derived classes can be used in place of
objects of their base classes?
Answer: c) Liskov Substitution Principle (LSP)
16. Which SOLID principle states that high-level modules should not depend on low-level
modules, but both should depend on abstractions?
Answer: a) Dependency Inversion Principle (DIP)
17. Which SOLID principle promotes the idea of single-minded classes with a specific
purpose?
Answer: a) Single Responsibility Principle (SRP)
18. Which SOLID principle focuses on the interface design between components?
Answer: d) Interface Segregation Principle (ISP)
19. Which SOLID principle helps in making the system more adaptable to changes by
extending rather than modifying existing code?
Answer: b) Open/Closed Principle (OCP)
20. Which SOLID principle suggests that high-level modules should not directly depend on
low-level modules, but both should depend on abstractions?
Answer: a) Dependency Inversion Principle (DIP)
21. Which SOLID principle emphasizes the importance of designing classes with a single,
well-defined responsibility?
Answer: a) Single Responsibility Principle (SRP)
22. Which SOLID principle focuses on making the system easier to test, extend, and
maintain?
Answer
23. Which SOLID principle promotes the idea of designing cohesive and focused interfaces?
Answer: d) Interface Segregation Principle (ISP)
24. Which SOLID principle ensures that objects of derived classes can be substituted for
objects of their base classes without breaking the program's correctness?
Answer: c) Liskov Substitution Principle (LSP)
25. Which SOLID principle encourages designing modules that depend on abstractions rather
than concrete implementations?
Answer: a) Dependency Inversion Principle (DIP)
26. Which SOLID principle suggests avoiding classes that have multiple responsibilities or
reasons to change?
Answer: a) Single Responsibility Principle (SRP)
27. Which SOLID principle promotes extending the functionality of a system by adding new
classes or components rather than modifying existing ones?
Answer: b) Open/Closed Principle (OCP)
28. Which SOLID principle advises splitting interfaces into smaller, more specific ones to
prevent unnecessary dependencies?
Answer: d) Interface Segregation Principle (ISP)
29. Which SOLID principle helps in designing robust and maintainable inheritance
hierarchies?
Answer: c) Liskov Substitution Principle (LSP)
30. Which SOLID principle suggests that the higher-level modules should not depend on the
lower-level modules, but both should depend on abstractions?
Answer: a) Dependency Inversion Principle (DIP)
Which of the following best describes the Open-Closed Principle (OCP)?
A. Modules should be designed to allow for easy replacement of components.
B. Classes should have only one reason to change.
C. Software entities should be open for extension but closed for modification.
D. A subclass should be able to replace its superclass without causing unexpected behavior
in the system.
Answer: C (Software entities should be open for extension but closed for modification)
Which of the following best describes the Dependency Inversion Principle (DIP)?
A. An object should depend on abstractions rather than concrete implementations.
B. Classes should have only one reason to change.
C. Software entities should be open for extension but closed for modification.
D. A subclass should be able to replace its superclass without causing unexpected behavior
in the system.
Answer: A (An object should depend on abstractions rather than concrete implementations)
Which of the following best describes the Single Responsibility Principle (SRP)?
A. Software entities should be open for extension but closed for modification.
B. A module should not be affected by changes to other modules.
C. A class should have only one reason to change.
D. A class should not be forced to implement methods that it does not need.
Answer: C (A class should have only one reason to change)
Which of the following best describes the Interface Segregation Principle (ISP)?
A. An object should depend on abstractions rather than concrete implementations.
B. Software entities should be open for extension but closed for modification.
C. A class should not be forced to implement methods that it does not need.
D. A module should not be affected by changes to other modules.
Answer: C (A class should not be forced to implement methods that it does not need)
Which of the following best describes the Liskov Substitution Principle (LSP)?
A. Modules should be designed to allow for easy replacement of components.
B. An object should depend on abstractions rather than concrete implementations.
C. A module should not be affected by changes to other modules.
D. A subclass should be able to replace its superclass without causing unexpected behavior
in the system.
Answer: D (A subclass should be able to replace its superclass without causing unexpected
behavior in the system)
Which SOLID principle recommends that an object should depend on abstractions rather
than concrete implementations?
A. Open-Closed Principle (OCP)
B. Dependency Inversion Principle (DIP)
C. Interface Segregation Principle (ISP)
D. Single Responsibility Principle (SRP)
Answer: B (Dependency Inversion Principle)
Which SOLID principle states that a module should not be affected by changes to other
modules?
A. Liskov Substitution Principle (LSP)
B. Single Responsibility Principle (SRP)
C. Open-Closed Principle (OCP)
D. Interface Segregation Principle (ISP)
Answer: C (Open-Closed Principle)
Which SOLID principle recommends that a class should have only one reason to change?
A. Single Responsibility Principle (SRP)
B. Interface Segregation Principle (ISP)
C. Liskov Substitution Principle (LSP)
D. Dependency Inversion Principle (DIP)
Answer: A (Single Responsibility Principle)
Which SOLID principle states that a class should not be forced to implement methods that it
does not need?
A. Single Responsibility Principle (SRP)
B. Liskov Substitution Principle (LSP)
C. Interface Segregation Principle (ISP)
D. Open-Closed Principle (OCP)
Answer: C (Interface Segregation Principle)
Which SOLID principle recommends that modules should be designed to allow for easy
replacement of components?
A. Dependency Inversion Principle (DIP)
B. Open-Closed Principle (OCP)
C. Single Responsibility Principle (SRP)
D. Liskov Substitution Principle (LSP)
Answer: A (Dependency Inversion Principle)
In software engineering, the SOLID principles are a set of five design principles
that help guide the development of robust and maintainable software systems.
Each principle focuses on a specific aspect of software design and promotes
modular, flexible, and reusable code. Here's a brief explanation of each
principle in an easy-to-understand way:
3. Liskov Substitution Principle (LSP): The LSP states that objects of a superclass
should be replaceable with objects of its subclasses without affecting the
correctness of the program. In other words, if you have a base class and you
create derived classes from it, you should be able to use those derived classes
wherever the base class is expected. This promotes polymorphism and helps
maintain the behavior and contracts of the base class.
4. Interface Segregation Principle (ISP): The ISP emphasizes that clients should
not be forced to depend on interfaces they don't use. Instead of having large
and bloated interfaces, it's better to create smaller and more focused
interfaces that cater to specific client needs. This principle helps prevent
coupling and ensures that clients only depend on what they actually require.