Free Practice Quiz Question List

6 Interfaces and Abstract Types Online Quiz Questions

Use this free practice quiz with 20 questions to review 6 Interfaces and Abstract Types, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Which statement best describes the primary purpose of an interface?

  1. A

    It must provide shared implementation and instance state for all implementing types.

  2. B

    It primarily defines a contract of supported operations that a type promises to provide.

  3. C

    It can be instantiated directly, even when required operations have no implementation.

  4. D

    It is limited to types that share one concrete database implementation.

02
Choose one
1 point

A family of related report types needs a shared title field, a constructor, and a common printHeader method, while each report supplies its own body-generation method. Which abstraction best fits this design?

  1. A

    Use an interface to define a capability without shared implementation.

  2. B

    Use unrelated concrete classes so no report type inherits behavior.

  3. C

    Use an abstract class that provides a partially implemented foundation for related subclasses.

  4. D

    Use a large interface requiring every report to implement unrelated operations.

03
Choose one
1 point

Which change best applies dependency inversion to an OrderService that must work with both a production database store and an in-memory test store?

  1. A

    Construct MySqlOrderStore inside OrderService so the service controls persistence directly.

  2. B

    Expose every database-specific method through OrderService.

  3. C

    Inject an object that conforms to OrderStore into OrderService.

  4. D

    Replace the database with a global variable accessed by all services.

04
Choose all
1 point

Select all elements that belong in a behaviorally precise interface contract.

  1. A

    Operation names and signatures

  2. B

    The private data structure used internally by every implementation

  3. C

    Rules for valid inputs and the meaning of results

  4. D

    Behavioral guarantees made to clients

  5. E

    Expected errors, exceptions, or rejected inputs

  6. F

    State and side-effect expectations, such as whether an operation changes data, performs I/O, or is safe to repeat

05
Choose all
1 point

Select all design choices that generally improve an interface's effectiveness.

  1. A

    Represent a coherent responsibility

  2. B

    Expose only the operations a client actually needs

  3. C

    Include every operation available on the concrete object

  4. D

    Avoid leaking framework-specific or internal data types

  5. E

    Make implementations easier to test and replace

06
True or false
1 point

True or false: A class can often implement multiple interfaces even though it usually has only one class base.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: Two implementations are interchangeable as long as their method names and signatures match, even if one violates the interface's documented guarantees.

  1. A

    True

  2. B

    False

08
Written response
1 point

What principle recommends that high-level policy depend on abstractions instead of directly on low-level implementation details?

09
Written response
1 point

What object-oriented design concept allows Checkout to call the same charge operation through PaymentProcessor while different concrete processors produce their own behavior?

10
Fill in the blank
1 point

Complete the statement with the contract element that documents errors, exceptions, or rejected inputs: A useful interface contract includes names and signatures, input and output rules, behavioral expectations, and .

11
Fill in the blank
1 point

Complete the statement: With dependency inversion, an application can select a concrete implementation at the while the consuming class receives the abstract type.

12
Open ended
1 point

Design an interface-based notification component for a checkout system. Explain the interface operation, at least two concrete implementations, important contract guarantees, and how the checkout client should receive the implementation. Also explain why this design improves replaceability or testing.

13
Choose one
1 point

A client only needs to read data, but a proposed interface also requires writing, printing, scanning, and faxing. Which redesign best follows the focused-interface principle?

  1. A

    Add every possible device operation to Reader so clients have more choices.

  2. B

    Separate reading from writing and other unrelated device capabilities.

  3. C

    Make every Reader implementation inherit from a concrete file-device class.

  4. D

    Expose the device's internal storage format through the interface.

14
Choose one
1 point

A cache abstraction promises that successful get operations return current values. Which situation makes a replacement cache invalid under the abstraction's contract?

  1. A

    It uses a different storage technology from the original implementation.

  2. B

    It returns stale data even though the cache contract promises current data.

  3. C

    It is selected through a constructor rather than a framework.

  4. D

    It stores values in a dictionary instead of process memory.

15
Choose one
1 point

A team is designing a common foundation for several closely related report types. The reports should share a title field, a constructor, and a method that prints a common header, while each report supplies its own body-generation method. Which abstraction best fits this requirement?

  1. A

    Define a capability that unrelated types can provide

  2. B

    Provide a common base with shared state and reusable implementation

  3. C

    Guarantee that only one concrete type can implement the behavior

  4. D

    Expose every operation available on each concrete type

16
Choose one
1 point

An OrderService currently creates a MySqlDatabase internally, making tests dependent on that database and making replacement difficult. Which redesign best applies dependency inversion?

  1. A

    Construct MySqlOrderStore inside OrderService so the database choice is centralized

  2. B

    Pass a concrete MySqlOrderStore to every method of OrderService

  3. C

    Define OrderStore and inject an implementation into OrderService

  4. D

    Copy the database operations directly into OrderService

17
True or false
1 point

True or false: A method signature by itself is a complete interface contract because it specifies the operation name and its parameters.

  1. A

    True

  2. B

    False

18
Choose one
1 point

A Cache abstraction promises that get(key) returns current data when a value exists. MemoryCache and RedisCache both provide the required operations, but RedisCache can return stale values. What conclusion follows?

  1. A

    The stale-data implementation is not interchangeable because it violates the contract

  2. B

    The implementations are interchangeable because both provide get and put methods

  3. C

    The implementations are interchangeable as long as their class names differ

  4. D

    The stale-data implementation is interchangeable if it uses a faster storage system

19
Written response
1 point

What object-oriented design term describes the ability of Checkout to call charge through the PaymentProcessor interface without knowing whether it received a CardProcessor, TestProcessor, or another implementation?

20
Written response
1 point

What design technique is illustrated when a constructor, factory, configuration object, or framework supplies a concrete implementation to a class that depends on an abstraction?