0% found this document useful (0 votes)
756 views14 pages

SW-2 Lecture 4 MCQ (SOLID)

The document contains 30 multiple choice questions about the SOLID principles of object-oriented design. The questions cover the Single Responsibility Principle, Open/Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle. The correct answers are provided for each question.

Uploaded by

samamostafa507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
756 views14 pages

SW-2 Lecture 4 MCQ (SOLID)

The document contains 30 multiple choice questions about the SOLID principles of object-oriented design. The questions cover the Single Responsibility Principle, Open/Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle. The correct answers are provided for each question.

Uploaded by

samamostafa507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

SW-2: MCQ on Lecture 4 (SOLD)

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)

3. The Liskov Substitution Principle (LSP) ensures:


a) Objects of a subclass can replace objects of a superclass without affecting the program's
correctness.
b) Objects of a superclass can replace objects of a subclass without affecting the program's
correctness.
c) Objects of a class can replace objects of any other class without affecting the program's
correctness.
d) Objects of a class cannot be replaced by objects of any other class.
Correct answer: a) Objects of a subclass can replace objects of a superclass without
affecting the program's correctness.

4. The Interface Segregation Principle (ISP) suggests:


a) Classes should have multiple responsibilities.
b) Clients should depend on interfaces they don't use.
c) Classes should depend on concrete implementations rather than abstractions.
d) Clients should only depend on the interfaces they actually require.
Correct answer: d) Clients should only depend on the interfaces they actually require.

5. Which SOLID principle promotes the use of abstraction to decouple components?


a) SRP
b) OCP
c) LSP
d) ISP
e) DIP
Correct answer: e) Dependency Inversion Principle (DIP)

6. The Single Responsibility Principle (SRP) encourages classes to have:


a) Multiple responsibilities.
b) No responsibilities.
c) Only one responsibility.
d) Responsibilities that can change frequently.
Correct answer: c) Only one responsibility.

7. According to the Open/Closed Principle (OCP), software entities should be:


a) Open for modification and closed for extension.
b) Open for extension and closed for modification.
c) Open for both modification and extension.
d) Closed for both modification and extension.
Correct answer: b) Open for extension and closed for modification.

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)

10. The Dependency Inversion Principle (DIP) suggests that:


a) High-level modules should directly depend on low-level modules.
b) Low-level modules should directly depend on high-level modules.
c) Both high-level and low-level modules should depend on each other.
d) High-level and low-level modules should depend on abstractions.
Correct answer: d) High-level and low-level modules should depend on abstractions.

11. Which SOLID principle helps prevent coupling and ensures clients only depend on

what they require?


a) SRP
b) OCP
c) LSP
d) ISP
e) DIP
Correct answer: d) Interface Segregation Principle (ISP)

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)

16. The Interface Segregation Principle (ISP) advises against:


a) Having small and focused interfaces
b) Having large and bloated interfaces
c) Having no interfaces at all
d) Having interfaces that are tightly coupled to implementation details
Correct answer: b) Having large and bloated interfaces

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)

9. Which SOLID principle prevents clients from depending on unnecessary functionality?


Answer: d) Interface Segregation Principle (ISP)

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

: b) Open/Closed Principle (OCP)

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)

What is the SOLID Principles?

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:

1. Single Responsibility Principle (SRP): This principle states that a class or


module should have only one reason to change. In other words, it should have
a single responsibility or job. By keeping classes focused on a specific task, you
can make them easier to understand, maintain, and test.

2. Open/Closed Principle (OCP): The OCP suggests that software entities


(classes, modules, etc.) should be open for extension but closed for
modification. This means that you should be able to add new features or
functionality without modifying existing code. By using techniques such as
inheritance, interfaces, and dependency injection, you can achieve this
principle.

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.

5. Dependency Inversion Principle (DIP): The DIP suggests that high-level


modules/classes should not depend on low-level modules/classes directly.
Instead, both should depend on abstractions. This principle encourages the use
of interfaces or abstract classes to define contracts and establish a level of
indirection. By doing so, you can decouple components, improve flexibility, and
facilitate easier testing and swapping of implementations.

These principles together provide guidance for designing software that is


modular, maintainable, and adaptable to change. By applying them, you can
create code that is easier to understand, extend, and modify, leading to more
robust and scalable software systems.

You might also like