Free Practice Quiz Question List

5 Polymorphism Online Quiz Questions

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

20 questions
01
Choose one
1 point

Which statement best describes the central value of polymorphism?

  1. A

    It requires every concrete type to use identical internal code.

  2. B

    It allows different concrete types to be used through a common abstraction.

  3. C

    It means that only subclasses can be instantiated.

  4. D

    It replaces all interfaces with concrete classes.

02
True or false
1 point

A variable is declared as Shape but refers to a Circle object. When a virtual Area() method is called, the declared type determines which override executes.

  1. A

    True

  2. B

    False

03
Written response
1 point

What mechanism causes shape.Area() to call Circle.Area() when the variable is declared as Shape but refers to a Circle?

04
Fill in the blank
1 point

A derived class that can be used wherever its more general type is expected has a relationship with that .

05
Choose one
1 point

A class DetailedReport overrides BaseReport.Format(), while HiddenReport hides the same method with new. Which statement correctly distinguishes the two designs?

  1. A

    The derived method is always ignored.

  2. B

    The compiler rejects every call through the base type.

  3. C

    A base-class reference can still reach the derived implementation.

  4. D

    The new keyword guarantees run-time dispatch.

06
Choose all
1 point

Which benefits follow from programming against an abstraction such as IPaymentProcessor? Select all that apply.

  1. A

    Implementations can change without requiring changes to clients.

  2. B

    Tests can provide fake or mock implementations.

  3. C

    The caller must know the concrete class used at run time.

  4. D

    New implementations can be added without modifying the caller.

07
True or false
1 point

An interface-based relationship requires all implementing classes to share a common implementation of their operations.

  1. A

    True

  2. B

    False

08
Written response
1 point

What design approach lets a Report contain an IFormatter and delegate rendering to it instead of inheriting from separate formatter-specific report classes?

09
Fill in the blank
1 point

The ability to replace a general type with a more specific type without breaking clients is called . It requires preserving the abstraction's .

10
Choose one
1 point

Which situation best illustrates duck typing?

  1. A

    The object must inherit from a specified base class.

  2. B

    The object is accepted if it provides the required behavior.

  3. C

    The compiler must generate a separate interface for every object.

  4. D

    Only objects with identical fields can be substituted.

11
Choose all
1 point

Which checks belong to a practical review of whether a subtype is safely substitutable? Select all that apply.

  1. A

    It can be passed wherever the supertype is expected.

  2. B

    It honors the supertype's preconditions and postconditions.

  3. C

    It may impose stronger requirements if its method signatures match.

  4. D

    It preserves important invariants of the abstraction.

12
Open ended
1 point

Explain how programming against abstractions supports changeability and testability. Use the payment-processor example or an equivalent design, and explain why substitutability still matters.

13
Choose one
1 point

Which guideline correctly distinguishes when inheritance or composition should be used?

  1. A

    Inheritance should be used whenever it avoids duplicated helper methods.

  2. B

    Composition is appropriate only when no interfaces exist.

  3. C

    Inheritance should express a genuine subtype relationship, while composition suits a “has a” relationship.

  4. D

    Composition prevents objects from using polymorphic behavior.

14
Choose one
1 point

Which description best captures the central value of polymorphism?

  1. A

    It requires every concrete type to use identical internal code.

  2. B

    It allows different concrete types to be used through a common abstraction with specialized behavior.

  3. C

    It means a caller must know the exact concrete class before invoking any operation.

  4. D

    It replaces all interfaces with static utility methods.

15
True or false
1 point

In duck typing, code can accept an object because it supports the required operations even when it does not explicitly inherit from a named type.

  1. A

    True

  2. B

    False

16
Choose one
1 point

Given Shape shape = new Circle(2);, which implementation is selected when shape.Area() is invoked, assuming Area() is overridden?

  1. A

    The call is rejected because Shape has no concrete implementation.

  2. B

    The call always executes Shape.Area() because Shape is the declared type.

  3. C

    The call executes Circle.Area() because Circle is the run-time type.

  4. D

    The call selects an overload based on the constructor expression.

17
Written response
1 point

What type relationship describes a class that promises to provide the operations specified by an interface?

18
Choose one
1 point

What is the important behavioral difference between using override and using new for a method in a derived C# class?

  1. A

    override preserves dynamic dispatch through a base-class reference, whereas new hides the member.

  2. B

    new preserves dynamic dispatch, whereas override makes the method private.

  3. C

    override and new always produce identical behavior through a base-class reference.

  4. D

    new can be used only with abstract members, whereas override can be used only with nonvirtual members.

19
Choose one
1 point

A function accepts values through a base abstraction. Which condition is necessary for a new subtype to be safely substitutable?

  1. A

    A subtype must expose more public methods than its supertype.

  2. B

    A subtype may reject inputs that the supertype accepts if its implementation is more specialized.

  3. C

    A subtype is substitutable whenever it inherits the same method names.

  4. D

    A subtype must preserve the supertype's behavioral expectations when used through the abstraction.

20
Written response
1 point

What design approach lets an object delegate work to contained objects that implement an abstraction?