Free Practice Quiz Question List

6 Interfaces and Abstractions Online Quiz Questions

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

20 questions
01
Choose one
1 point

Which statement best describes an interface?

  1. A

    A concrete algorithm that every client must use

  2. B

    A contract of operations or members that an implementing type must provide

  3. C

    A database schema shared by all application components

  4. D

    A class that can always be instantiated directly

02
Choose one
1 point

Why might a closely related family of types use an abstract class instead of only an interface?

  1. A

    It can combine incomplete behavior with shared implementation or state

  2. B

    It must contain only abstract members and no implementation

  3. C

    It can be instantiated directly in every object-oriented language

  4. D

    It is limited to unrelated classes that share one capability

03
Choose one
1 point

Which design best applies dependency injection to an OrderService that needs to charge payments?

  1. A

    Constructing StripePaymentGateway inside OrderService

  2. B

    Making OrderService inherit from every payment gateway

  3. C

    Passing a PaymentGateway into OrderService from outside

  4. D

    Removing the payment operation from OrderService

04
Choose all
1 point

Which two situations are especially appropriate for using an interface? Select all correct answers.

  1. A

    The capability may apply to unrelated classes.

  2. B

    Subclasses need substantial shared state and construction rules.

  3. C

    One class needs several independent capabilities.

  4. D

    A base class must control a shared algorithm and protected implementation.

05
Choose all
1 point

Which two outcomes can result when application logic depends on a focused abstraction rather than a concrete infrastructure class? Select all correct answers.

  1. A

    Every implementation must use the same algorithm internally.

  2. B

    Implementations can be exchanged more easily.

  3. C

    A client automatically gains access to vendor-specific details.

  4. D

    Tests can supply fakes or mocks.

06
True or false
1 point

In structural typing, a type can satisfy an interface without explicitly declaring that it implements the interface.

  1. A

    True

  2. B

    False

07
True or false
1 point

If two classes have matching method signatures, they necessarily fulfill the same abstraction contract.

  1. A

    True

  2. B

    False

08
Written response
1 point

What is the object-oriented concept that lets a function use Book, Subscription, and ServicePlan objects through the common PricedItem abstraction while each calculates its price differently?

09
Written response
1 point

What typing approach allows a type to satisfy an interface because it has the required members, even without explicitly declaring the relationship?

10
Fill in the blank
1 point

Complete the statement: An describes essential behavior while hiding implementation details, and an is a concrete type that fulfills that contract.

11
Fill in the blank
1 point

Complete the statement: Supplying a PaymentGateway to OrderService from outside, rather than constructing the gateway inside the service, is an example of .

12
Open ended
1 point

You are designing an application service that currently creates a database client directly and returns database-specific records. Describe a better design using abstractions and dependency injection. Explain how your design affects testing and infrastructure changes, and identify one behavioral detail that the abstraction's contract should document.

13
Choose one
1 point

What is a likely design problem with an interface that contains many unrelated operations?

  1. A

    It prevents any class from implementing more than one interface.

  2. B

    It guarantees that all implementations share the same internal algorithm.

  3. C

    It can force implementations to provide unrelated operations they do not need.

  4. D

    It makes structural typing impossible.

14
Choose one
1 point

Which statement best describes an abstraction in object-oriented programming?

  1. A

    It describes essential behavior without exposing every implementation detail.

  2. B

    It requires every class to inherit from the same concrete base class.

  3. C

    It stores all application data in a shared database.

  4. D

    It guarantees that a program has multiple implementations of every type.

15
True or false
1 point

True or false: An abstract class normally cannot be instantiated directly.

  1. A

    True

  2. B

    False

16
Choose one
1 point

A system must allow invoices, photographs, and maps to be printable, even though these types are unrelated and should not share implementation or state. Which design best represents this requirement?

  1. A

    Define an abstract class because every type must share the same inheritance hierarchy.

  2. B

    Define a small interface because invoices, photographs, and maps are unrelated types that share the Printable capability.

  3. C

    Make each type inherit from a separate concrete printing class.

  4. D

    Put all printing logic into the user-interface layer.

17
Choose one
1 point

An OrderService needs to charge payments. The design should support a real gateway in production and a fake gateway in isolated tests without changing OrderService. Which approach best applies dependency injection?

  1. A

    Have OrderService always construct StripePaymentGateway internally.

  2. B

    Make the database create the payment gateway when an order is saved.

  3. C

    Pass a PaymentGateway into OrderService so production and test implementations can be supplied externally.

  4. D

    Copy the payment code into every method that processes an order.

18
Choose one
1 point

In a structural type system using a Closeable protocol, a File type defines the required close operation but does not explicitly declare that it implements Closeable. What does this imply?

  1. A

    A File object with a close operation can be accepted as Closeable even without explicitly declaring that relationship.

  2. B

    A File object must inherit from a class named Closeable before it can be accepted.

  3. C

    The compiler accepts only objects whose method names are chosen at runtime.

  4. D

    A type satisfies the interface only when it has more members than the interface requires.

19
Written response
1 point

What programming term describes the ability of one interface-typed parameter to refer to objects such as a Book, Subscription, or ServicePlan, each of which can implement an operation differently?

20
Written response
1 point

What is the programming term for a member declared by an abstract class that specifies behavior a concrete subclass must provide?