Which statement best explains the relationship between a class and an object?
1 Object-Oriented Programming Foundations Online Quiz Questions
Use this free practice quiz with 20 questions to review 1 Object-Oriented Programming Foundations, test your knowledge, and prepare for your next test or exam.
A bank-account class rejects invalid deposits through methods instead of allowing callers to assign directly to its balance. Which OOP principle is most directly illustrated?
- A
It controls access to internal state through a useful public interface.
- B
It requires every class to inherit from exactly one superclass.
- C
It replaces all methods with publicly accessible fields.
- D
It makes implementation details visible to every client.
A Car stores an Engine object and delegates start() to that engine. Which relationship and design mechanism does this example primarily represent?
- A
Inheritance, because Car and Engine must share a superclass.
- B
Abstraction, because the engine's implementation is hidden.
- C
Composition, because a Car contains an Engine as a part.
- D
Polymorphism, because every object must have the same behavior.
A payment service depends on the Payable contract instead of directly depending on Employee or Contractor. Which two statements correctly describe the role of the interface in this design? Select all correct choices.
- A
It defines operations that an implementing class promises to provide.
- B
It requires every implementing class to inherit implementation from one concrete superclass.
- C
It allows client code to depend on a capability rather than a concrete payment class.
- D
It exposes all internal fields of each implementing class.
Which two design guidelines are consistent with the material's treatment of inheritance and composition? Select all correct choices.
- A
Inheritance should be used whenever it avoids duplicating a few lines of code.
- B
A subclass should honor the promises and expectations of its base type.
- C
A class should expose all of its dependencies as public fields to maximize reuse.
- D
Composition is often preferable when behavior may vary independently or reuse is the main goal.
True or false: A caller can use an account's withdraw(25) operation without knowing whether the account stores data in memory, a database, or a remote service.
- A
True
- B
False
True or false: Object-oriented programming eliminates the need for functions, loops, and conditionals.
- A
True
- B
False
What OOP concept allows a variable of general type Shape to refer to a Circle while the call to area() uses the Circle implementation?
What term names the operation that establishes the initial valid state of a newly created object?
An object combines —the information stored in its fields—with —the operations provided by its methods.
A subclass should be used when it has a genuine relationship with its superclass, such as SavingsAccount with BankAccount.
Explain how polymorphism reduces conditional logic in a program. Use the Shape, Circle, and Rectangle example or an equivalent example grounded in the material.
Which design best applies dependency injection to an OrderService that must work with multiple payment providers?
- A
Make OrderService construct a specific database-backed payment provider internally.
- B
Make OrderService depend on a PaymentProcessor interface and receive a concrete processor through its constructor.
- C
Copy payment-storage logic into every OrderService method.
- D
Make every payment provider inherit all of OrderService's implementation.
True or false: A class that manages billing, user authentication, file storage, and screen layout has strong cohesion because it centralizes many related system features.
- A
True
- B
False
Which statement best describes the central emphasis of object-oriented programming?
- A
OOP prohibits the use of functions and loops.
- B
OOP treats entities and their responsibilities as central design units.
- C
OOP requires every class to inherit from another class.
- D
OOP means that all implementation details must be public.
What is the technical term for a contract that specifies operations an implementing class promises to provide?
A bank-account class prevents callers from assigning an arbitrary balance and requires them to use operations that enforce validity rules. Which design principle is most directly illustrated?
- A
Encapsulation protects internal representation and supports controlled interaction through a public interface.
- B
Encapsulation means exposing all fields so clients can update them directly.
- C
Encapsulation requires every class to have a subclass.
- D
Encapsulation and abstraction are exactly the same practice.
A developer is deciding whether to make SavingsAccount inherit from BankAccount. Which condition provides the strongest design justification?
- A
Inheritance is justified whenever two classes have similarly named methods.
- B
Inheritance is justified when the subclass needs to access private fields directly.
- C
Inheritance is justified when the subclass is a substitutable specialized form of the superclass.
- D
Inheritance is justified whenever it avoids duplicating any code.
What OOP concept allows a variable of general type Shape to refer to a Circle while a call to area() uses the circle-specific implementation?
Which design choice best supports high cohesion in an object-oriented system?
- A
A class should expose every implementation detail to maximize flexibility.
- B
A class should combine unrelated services so clients need only one dependency.
- C
A class should inherit from as many classes as possible to maximize reuse.
- D
A class should represent a meaningful concept with a focused set of responsibilities.