What does the single responsibility principle encourage?
A One reason to change
B One method in every class
C One object in each program
D One base for all types
Answer: A. One reason to change. A class should have one focused responsibility and one main reason to change.
What does the Liskov substitution principle require?
A Subtypes remove all base methods
B Subtypes preserve base expectations
C Every class inherits one base
D Base types depend on subtypes
Answer: B. Subtypes preserve base expectations. Subtypes should work without violating the promises made by their base types.
What does interface segregation recommend?
A Large interface for all clients
B Several focused client interfaces
C No interfaces in a system
D Interfaces with private methods only
Answer: B. Several focused client interfaces. Focused interfaces prevent clients from depending on operations they do not use.
What does dependency inversion recommend?
A All code uses concrete classes
B High level depends on abstractions
C Subclasses call global state
D Interfaces depend on objects only
Answer: B. High level depends on abstractions. Dependency inversion separates high level policy from low level implementation details.
What is a UML class diagram used to show?
A Program execution time
B Memory bytes at runtime
C Classes and their relationships
D Only user interface colors
Answer: C. Classes and their relationships. A class diagram models types, members, and relationships among classes.
What does a UML inheritance arrow indicate?
A Object composition only
B Method parameter flow
C A runtime exception
D Generalization relationship
Answer: D. Generalization relationship. A generalization arrow represents inheritance from a more specific class to a general one.
What does a multiplicity such as 1..* express?
A Method return type
B Allowed relationship count
C Class memory size
D Inheritance depth
Answer: B. Allowed relationship count. Multiplicity states how many related objects may participate in an association.
What is a sequence diagram used to show?
A Messages over time
B Class fields by visibility
C Object memory layout
D Only data types
Answer: A. Messages over time. A sequence diagram shows interactions between participants in time order.
What is a unit test for an object class?
A Compile all project files only
B Test network throughput
C Test class behavior alone
D Measure source lines
Answer: C. Test class behavior alone. A unit test exercises a small class behavior independently of the larger system.
What is a mock object?
A Production singleton instance
B Subclass constructor only
C Object's deep copy
D Test double simulating collaborator
Answer: D. Test double simulating collaborator. A mock simulates a dependency and can record expected interactions during tests.
What is a code smell?
A Sign of possible design problem
B Guaranteed compiler error
C A required design pattern
D A runtime object address
Answer: A. Sign of possible design problem. A code smell suggests an area may need review or refactoring.
Why prefer composition over deep inheritance in many designs?
A It reduces rigid coupling
B It prevents code reuse
C It removes all interfaces
D It guarantees zero bugs
Answer: A. It reduces rigid coupling. Composition can combine behavior without tightly binding classes into deep hierarchies.
What is the fragile base class problem?
A Base change unexpectedly breaks subclasses
B Base classes cannot contain methods
C Subclass cannot override anything
D Constructor always runs twice
Answer: A. Base change unexpectedly breaks subclasses. Changes to a base class can have unintended effects on derived classes.
What does a sealed hierarchy help control?
A How objects are allocated
B Which fields are mutable
C Which types may extend it
D How constructors are named
Answer: C. Which types may extend it. Sealed types restrict which classes can be direct or indirect subtypes.
What is an abstract factory used to create?
A A single primitive value
B One sorted list
C A runtime call stack
D Related families of objects
Answer: D. Related families of objects. An abstract factory creates families of related objects without naming their concrete classes.
What does the adapter pattern do?
A Adds behavior by wrapping
B Notifies observers of change
C Makes incompatible interfaces work together
D Selects one algorithm at runtime
Answer: C. Makes incompatible interfaces work together. An adapter translates one interface into another expected by a client.
What does the facade pattern provide?
A A subtype with no fields
B A copy of every object
C A method's return value
D Simplified interface to subsystem
Answer: D. Simplified interface to subsystem. A facade offers a simpler entry point over a more complex subsystem.
What does the command pattern encapsulate?
A Request as an object
B Object state as a field
C Class name as a string
D Inheritance as a graph
Answer: A. Request as an object. A command packages a request so it can be queued, logged, or invoked later.
What does the template method pattern define?
A A family of factory objects
B One global instance
C Algorithm skeleton in base class
D A mutable list of observers
Answer: C. Algorithm skeleton in base class. A base class fixes an algorithm outline while subclasses fill selected steps.
What does the builder pattern help construct?
A One method through inheritance
B Complex objects step by step
C Graph edges in sorted order
D Objects without constructors ever
Answer: B. Complex objects step by step. A builder separates a complex object's construction steps from its representation.
Why use immutable value objects?
A Faster mutation in every case
B Avoid all constructors
C Allow global state changes
D Safer sharing and predictable state
Answer: D. Safer sharing and predictable state. Immutable value objects are easier to share because their state cannot change unexpectedly.
What is an object's lifecycle?
A Only method invocation order
B Compilation and linking
C Sorting and searching phases
D Creation, use, and cleanup stages
Answer: D. Creation, use, and cleanup stages. An object's lifecycle includes construction, use, and eventual cleanup.
What does polymorphic behavior enable?
A Generic code for many subtypes
B One concrete class only
C No method calls at runtime
D All fields public
Answer: A. Generic code for many subtypes. Polymorphism lets common code work with different implementations behind a shared type.
What is a design pattern?
A A programming language keyword
B A compiler optimization
C Reusable design template
D A required class diagram
Answer: C. Reusable design template. A design pattern names a commonly useful structure for a recurring design problem.
What is a bounded context in domain design?
A Class field size limit
B Model boundary with shared meaning
C Maximum method parameter count
D A test case range
Answer: B. Model boundary with shared meaning. A bounded context defines where a domain model and its terminology apply.