What is aggregation?
A Subclass method replacement
B Compile time method selection
C Weaker whole part relationship
D Object copying by value only
Answer: C. Weaker whole part relationship. Aggregation represents a whole part relationship where the part can exist independently.
How does composition differ from aggregation?
A Part must be a superclass
B Composition prevents methods
C Part lifetime tied to whole
D Aggregation requires same class
Answer: C. Part lifetime tied to whole. Composition usually gives the whole stronger ownership over component lifetimes.
What is dependency between classes?
A One class extends every type
B Two objects share an address
C One class uses another
D A field has no value
Answer: C. One class uses another. A dependency occurs when a class relies on another to perform some work.
What is constructor chaining?
A A constructor recursively loops forever
B A destructor creates an object
C A method overrides a field
D One constructor invokes another
Answer: D. One constructor invokes another. Constructor chaining reuses initialization by invoking another constructor.
Why call a superclass constructor?
A Delete parent methods
B Make private fields public
C Avoid creating the subclass
D Initialize inherited state
Answer: D. Initialize inherited state. A derived constructor may call its base constructor to initialize inherited fields.
What is object identity?
A Same object identity
B Whether two values are equal
C The object's class name
D The order it was constructed
Answer: A. Same object identity. Identity checks whether references point to the same object instance.
What is value equality?
A Whether references share an address
B Whether objects represent equivalent data
C Whether classes share a base
D Whether objects have same methods
Answer: B. Whether objects represent equivalent data. Value equality compares the represented contents or meaning of objects.
What is shallow copying?
A Copies entire object graph
B Moves the object to disk
C Copies top level fields
D Duplicates class definitions
Answer: C. Copies top level fields. A shallow copy duplicates an object but may retain references to the same nested objects.
What is deep copying?
A Copies only the outer reference
B Copies nested reachable objects
C Shares every nested object
D Converts object to an interface
Answer: B. Copies nested reachable objects. A deep copy recursively duplicates nested mutable objects when possible.
What can a mutable object change?
A Its class name always
B Its state after creation
C Its method signature
D Its type hierarchy
Answer: B. Its state after creation. A mutable object permits updates to its state after it is created.
What does immutability mean?
A State cannot change after creation
B Object has no fields
C Object cannot be referenced
D Methods cannot return values
Answer: A. State cannot change after creation. Immutable objects retain the same state throughout their lifetime.
What is object aliasing?
A Multiple references to same object
B Two classes with same name
C Two fields with equal values
D One object without a class
Answer: A. Multiple references to same object. Aliasing occurs when different references point to one object.
Why can aliasing cause bugs?
A Objects stop being mutable
B Methods cannot be called
C Classes become abstract
D Changes visible through other references
Answer: D. Changes visible through other references. A mutation through one alias is visible through other references to the same object.
What does garbage collection reclaim?
A All objects only at exit
B All class definitions
C Objects still in use
D Unreachable managed objects
Answer: D. Unreachable managed objects. Garbage collectors reclaim objects that are no longer reachable in managed runtimes.
What is deterministic resource cleanup?
A Automatic random memory freeing
B Explicit release at known point
C A class without a destructor
D A field initialized twice
Answer: B. Explicit release at known point. Deterministic cleanup releases resources at a predictable program point.
What is RAII in C++?
A Resource follows object lifetime
B A runtime interface for arrays
C Random access inheritance scheme
D A method dispatch algorithm
Answer: A. Resource follows object lifetime. RAII uses object construction and destruction to manage resource lifetimes.
What is a factory method used for?
A Sort objects by class
B Compare object identity
C Release memory manually
D Encapsulate object creation choice
Answer: D. Encapsulate object creation choice. A factory method centralizes or varies the creation of objects.
What is a singleton pattern intended to ensure?
A One method per class
B Every object is immutable
C One shared instance
D No object can be created
Answer: C. One shared instance. A singleton provides one controlled shared instance of a type.
What does the observer pattern define?
A One to many notification
B Whole part ownership
C Subclass constructor chaining
D An object sorting order
Answer: A. One to many notification. Observers receive updates when a subject's state changes.
What does the strategy pattern encapsulate?
A A single global object
B A class hierarchy diagram
C Object memory allocation
D Interchangeable algorithms
Answer: D. Interchangeable algorithms. Strategy lets clients choose among interchangeable behaviors through a common interface.
What does the decorator pattern add?
A A new inheritance root
B A global variable
C Behavior around an object
D A sorted object collection
Answer: C. Behavior around an object. Decorators wrap objects to add behavior while preserving a shared interface.
What does dependency injection provide?
A Dependencies from outside
B Fields directly from subclasses
C Runtime method names only
D Methods without parameters
Answer: A. Dependencies from outside. Dependency injection supplies a component's collaborators rather than constructing them internally.
What does coupling measure?
A Methods per class only
B Dependency between components
C Object size in bytes
D Number of tests run
Answer: B. Dependency between components. Coupling describes how strongly one component depends on another.
What does cohesion measure?
A Relatedness of class responsibilities
B Inheritance depth only
C Number of constructor arguments
D Class memory address
Answer: A. Relatedness of class responsibilities. High cohesion means a class's responsibilities fit together closely.
What does the open closed principle suggest?
A Open every field to public
B Extend without modifying
C Close all classes to inheritance
D Change every client
Answer: B. Extend without modifying. Software should allow new behavior with limited changes to stable existing code.