This exam assesses advanced understanding of object-oriented programming fundamentals, including abstraction,
encapsulation, inheritance, polymorphism, and design principles. Questions require deep conceptual reasoning
and application to complex scenarios. It contains 92 multiple-choice questions, each with four distractors and a
fully worked rationale that explains why the keyed answer is correct. Content is organized into 10 focused
sections: Introduction to Object-Oriented Programming, Classes and Objects, Inheritance and Polymorphism,
Exception Handling, File I/O and Streams, Generics and Collections, Graphical User Interfaces (GUIs),
Multithreading, Design Patterns, Recursion and Algorithm Analysis. Targeted learning outcomes include:
Critically analyze OOP concepts and their implications in software design.; Apply design principles to solve
complex problems.; Evaluate trade-offs between different OOP mechanisms.. Every item has been reviewed for
clinical accuracy, current guidelines, and clarity so that students can study with confidence and self-correct as
they work through the bank. Use it as a high-yield review immediately before the exam, or as a structured practice
tool during the unit - the rationales double as concise teaching notes. The recommended writing time is 3 hours,
with a passing score of 70%. Aligned with This exam meets the rigorous standards of top US R1 universities,
including Harvard, MIT, and Stanford. standards and reflects the question style commonly seen on accredited
program examinations. Students consistently achieving above the cut score on this bank have historically gone on
Section 1: Introduction to Object-Oriented Programming (Questions 1-9)
1 Consider the following Java-like code: class A { public void f() { print("A");
} } class B extends A { public void f() { print("B"); } } A obj = new B();
obj.f(); What is the output and why?
A) "A" because static type is A, and Java uses static binding for methods.
B) "B" because dynamic dispatch selects the method based on runtime type.
C) Compilation error because method overriding requires @Override
annotation.
D) "A" because constructors are not polymorphic.
Answer: B
Rationale: In Java, instance methods are dynamically dispatched. Even though
obj is declared as type A, the actual object is of type B, so B's f() is called.
Option A is wrong because Java uses dynamic binding for instance methods.
Option C is false; @Override is optional. Option D is irrelevant to method
calls.
2 Which of the following best describes the Liskov Substitution Principle
(LSP) in object-oriented design?
A) Subtypes must be substitutable for their base types without altering the
correctness of the program.
B) A class should have only one reason to change.
C) Depend upon abstractions, not concretions.
,D) Interfaces should be small and client-specific.
Answer: A
Rationale: The Liskov Substitution Principle states that objects of a superclass
should be replaceable with objects of a subclass without affecting the
correctness of the program. Option B is the Single Responsibility Principle, C
is the Dependency Inversion Principle, and D is the Interface Segregation
Principle.
3 In a language that supports multiple inheritance (like C++), which of the
following problems can arise and how is it typically resolved?
A) Ambiguity from two base classes having methods with the same name;
resolved by using virtual inheritance.
B) Memory leaks due to diamond problem; resolved by using garbage
collection.
C) Compilation errors due to conflicting member variables; resolved by using
namespaces.
D) Runtime performance degradation; resolved by using inline functions.
Answer: A
Rationale: Multiple inheritance can lead to the diamond problem where a class
inherits from two classes that share a common ancestor, causing ambiguity.
Virtual inheritance solves this by ensuring only one instance of the base class is
inherited. Option B is incorrect; garbage collection is unrelated. Option C is
not a standard resolution. Option D is not specific to multiple inheritance.
4 Which of the following is a key advantage of using composition over
inheritance in object-oriented design?
A) Composition allows code reuse without exposing the internal details of the
composed classes.
B) Composition is always more efficient at runtime than inheritance.
C) Composition eliminates the need for polymorphism.
D) Composition guarantees that the system is free from circular
dependencies.
Answer: A
Rationale: Composition promotes encapsulation by using objects as
components, hiding their implementation. Option B is false; performance
depends on context. Option C is false; composition does not eliminate
,polymorphism. Option D is false; circular dependencies can still occur.
5 In the context of object-oriented programming, what is the purpose of an
abstract class?
A) To provide a common base class that cannot be instantiated and may
contain abstract methods that subclasses must implement.
B) To allow multiple inheritance by merging interfaces.
C) To improve performance by inlining method calls.
D) To enforce that all subclasses have a common constructor signature.
Answer: A
Rationale: Abstract classes serve as base classes that cannot be instantiated and
can define abstract methods (without implementation) that subclasses must
override. Option B describes interfaces or mixins. Option C is unrelated.
Option D is not a purpose of abstract classes.
6 Which of the following is a potential drawback of using deep inheritance
hierarchies in object-oriented systems?
A) Increased code duplication due to the need to override many methods.
B) Difficulty in understanding the flow of control and increased coupling.
C) Improved performance due to more efficient method dispatch.
D) Simplified testing because each class can be tested in isolation.
Answer: B
Rationale: Deep inheritance hierarchies can make the system hard to understand
and maintain because changes in a base class can affect many subclasses,
increasing coupling. Option A is not necessarily true; duplication may not
increase. Option C is false; deep hierarchies can degrade performance. Option
D is false; testing becomes more complex.
7 In object-oriented programming, what is the difference between overloading
and overriding?
A) Overloading occurs when two methods have the same name but different
parameters; overriding occurs when a subclass provides a specific
implementation of a method already defined in its superclass.
B) Overloading is compile-time polymorphism; overriding is runtime
polymorphism.
C) Both A and B are correct.
, D) Overloading is runtime polymorphism; overriding is compile-time
polymorphism.
Answer: C
Rationale: Overloading (same name, different parameters) is resolved at
compile time, while overriding (subclass redefines a superclass method) is
resolved at runtime via dynamic dispatch. Thus both A and B are correct.
Option D reverses the definitions.
8 Consider the following Python code:
class A:
def method(self):
print("A")
class B(A):
pass
class C(A):
def method(self):
print("C")
class D(B, C):
pass
obj = D()
obj.method()
What is the output and why?
A) "A" because B inherits from A, so D uses A's method.
B) "C" because of Python's method resolution order (MRO) which follows
C3 linearization.
C) Error because D has ambiguous method resolution.
D) "A" because Python uses depth-first left-to-right order.
Answer: B
Rationale: Python uses C3 linearization for MRO. For class D(B, C), the MRO
is D -> B -> C -> A. Since C overrides method and appears before A, C's
method is called. Option A is incorrect because MRO is not simply depth-first.
Option C is false; Python resolves it. Option D describes old-style class MRO,
not current Python.
9 Which design pattern is most appropriate when you need to ensure that a
class has only one instance and provide a global point of access to it?