Object Oriented Programming Quiz

Questions: 16 · 10 minutes
1. You need to add logging or caching around a service at runtime without creating many subclasses or changing the service implementation. Which pattern is the best fit?
Singleton
Factory Method
Template Method
Decorator
2. A BankAccount must never have a negative balance. Which design most directly protects this class invariant?
Allow direct balance updates and check the value only when displaying it
Store the balance in several public fields for comparison
Restrict uncontrolled mutation and ensure every public operation preserves the rule
Let calling code decide whether each withdrawal is valid
3. Two Customer objects are separate instances but contain the same account number and customer data. Which statement correctly distinguishes identity from value equality?
They must have the same identity because their data matches
They can be value-equal while still having different object identities
They must be value-unequal because they were constructed separately
Identity and value equality are always interchangeable in OOP
4. Which description best captures encapsulation in object-oriented programming?
Defining several classes with the same method names
Keeping only the essential features of a concept in a model
Creating a new class by extending an existing class
Bundling state with related behavior while controlling direct access to that state
5. What is a constructor primarily responsible for in a well-designed class?
Establishing the object's initial state and required dependencies
Choosing which overridden method will run at compile time
Granting every other class direct access to internal fields
Destroying the object when it is no longer referenced
6. An OrderService directly creates and uses a SqlOrderRepository. Which change best follows the dependency inversion principle?
Make OrderService depend on an injected repository abstraction
Move all OrderService methods into SqlOrderRepository
Create the repository in a static global variable
Let SqlOrderRepository inherit from OrderService
7. A program sends the same draw() call to Circle, Rectangle, and Triangle objects, and each object responds differently. Which concept does this illustrate?
Encapsulation
Polymorphism
Object composition
Constructor chaining
8. Which relationship most strongly supports the appropriate use of inheritance?
The new class contains an instance of the existing class
The new class temporarily calls methods on the existing class
The two classes happen to store similar fields
The new class is a specialized type that can stand in for the existing type
9. A Bird base class requires every subtype to implement fly(). A Penguin subtype can only implement it by throwing an unsupported-operation error. What is the best redesign?
Move flying behavior into a separate capability implemented only by birds that fly
Make Penguin override every method in Bird
Add a type check before every call to fly()
Keep fly() in Bird and return false for penguins
10. What is the main purpose of abstraction in object-oriented design?
To ensure every class inherits from another class
To expose every field needed by collaborating objects
To model essential behavior while hiding unnecessary implementation detail
To convert all instance methods into static methods
11. An OrderService calls an external payment provider. How can you most effectively unit-test the service without making real payment requests?
Copy the payment provider's production code into the test
Make the real payment request and immediately reverse the transaction
Inject a payment-gateway abstraction and substitute a controlled test double
Remove the payment call from OrderService during testing
12. A Money object should be immutable. Which implementation choice best supports that goal?
Expose its amount field so callers can update it directly
Provide setters that silently reject some changes
Keep its state read-only after construction and return new objects for changed values
Store one shared mutable amount for all Money instances
13. A MultiFunctionDevice interface requires print(), scan(), and fax(), but a basic printer can only print. Which redesign best follows interface segregation?
Make the printer methods public fields instead
Split the interface into smaller printing, scanning, and faxing capabilities
Move all three methods into a common abstract superclass
Have the basic printer throw errors for scan() and fax()
14. A Car needs an Engine, but different engine implementations may be installed or replaced. Which design best represents this relationship?
Make Engine inherit from Car
Store all engine operations as global functions
Duplicate the engine behavior inside every Car class
Give Car an Engine reference supplied through composition
15. An application must support new export formats without repeatedly modifying tested export classes. Which design best supports the open/closed principle?
Define an exporter abstraction and add a new implementation for each format
Place every format algorithm in one large exporter class
Add a growing conditional statement for every format
Copy the existing exporter and rename its public methods
16. A variable declared as PaymentMethod refers at runtime to a CreditCardPayment object. When an overridden process() method is called, the credit-card implementation runs. What mechanism selected that method?
Compile-time method overloading
Dynamic dispatch
Constructor delegation
Field shadowing
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test