Object Oriented Programming
3.0 Credits
Midterm Exam Review (Qns & Ans)
2025
©2025
, Multiple Choice Questions
1. Question:
In languages such as C++ that support multiple inheritance,
which issue is commonly encountered that can be resolved by
virtual (or shared) inheritance?
- a. Code redundancy
- b. Ambiguity in method resolution (the "diamond problem")
- c. Runtime polymorphism errors
- d. Inefficient memory allocation
ANS:
b. Ambiguity in method resolution (the "diamond problem")
Rationale:
In multiple inheritance, the diamond problem occurs when a
derived class inherits from two classes that both inherit from a
common base. Virtual inheritance helps resolve this ambiguity by
ensuring that only one instance of the common base is included.
2. Question:
In Java, the overriding of methods defined in a superclass to
provide specialized behavior in a subclass is an example of:
- a. Encapsulation
- b. Overloading
- c. Dynamic polymorphism
- d. Static binding
ANS:
c. Dynamic polymorphism
Rationale:
Dynamic polymorphism (or runtime polymorphism) occurs when a
subclass overrides a method of its superclass, and the call is
resolved at runtime based on the actual object type.
3. Question:
©2025
, Which SOLID principle states that a class should have only one
reason to change?
- a. Open/Closed Principle
- b. Liskov Substitution Principle
- c. Single Responsibility Principle
- d. Dependency Inversion Principle
ANS:
c. Single Responsibility Principle
Rationale:
The Single Responsibility Principle emphasizes that a class
should have only one responsibility or reason to change, promoting
high cohesion and low coupling.
4. Question:
What is the primary advantage of using an abstract class in
OOP?
- a. It allows multiple inheritance across different classes
- b. It provides a common base with some implemented behavior
while enforcing a contract for subclasses
- c. It guarantees runtime performance improvements
- d. It automatically supports operator overloading
ANS:
b. It provides a common base with some implemented behavior
while enforcing a contract for subclasses
Rationale:
Abstract classes allow you to define some common behavior for
all subclasses while also declaring abstract methods that must be
implemented, ensuring a consistent interface.
5. Question:
Which of the following is an advantage of using composition over
inheritance in object-oriented design?
- a. It enables dynamic behavior changes at runtime
- b. It simplifies the syntax of class definitions
©2025