← All exam tracks
Object-Oriented Programming · Design
OOPS
Practice original scenario-based OOPS questions. Take a timed mock, focus on a topic, and learn from detailed explanations. These are independent practice materials, not official exam questions or a guarantee of certification readiness.
16 questions · 24 minutes · 70% practice target
Create an account to practice
Already a member? Sign in
Topics you will practice
- Objects & Contracts
- SOLID & Composition
- Design Patterns
- Testing & Refactoring
Try a sample
Think through each question, then reveal the explanation. Full attempts save your answers and scores to your account.
A BankAccount exposes a writable balance property. Callers can set negative values despite a withdrawal rule. Which change protects the invariant?
- Restrict direct mutation and expose operations that enforce the rule
- Rename balance to publicBalance
- Document that callers should behave
- Move the property to a global variable
Show answer and explanation
Correct answer: Restrict direct mutation and expose operations that enforce the rule
Encapsulation makes valid state transitions explicit and enforceable. Naming and documentation alone do not prevent invalid writes; global mutable state weakens control.
A family of exporters shares implemented code, but the base must not be instantiated and each subclass must supply format(). Which construct fits?
- A final base class intended for subclassing
- An interface containing ordinary shared method bodies
- A global variable containing the method name
- An abstract base class with an abstract format method
Show answer and explanation
Correct answer: An abstract base class with an abstract format method
An abstract class can combine implementation and required methods while preventing direct instantiation. final prevents subclassing; interfaces express contracts rather than this shared base implementation.
In PHP, a base-class helper should be callable inside the class and its subclasses, but not by unrelated callers. Which visibility fits?
- public
- static
- protected
- private
Show answer and explanation
Correct answer: protected
protected permits class-family access. private restricts access to the defining class; public permits external access. static concerns instance association, not visibility.
Study references