Which statement best describes the central value of polymorphism?
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.
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.
- A
True
- B
False
What mechanism causes shape.Area() to call Circle.Area() when the variable is declared as Shape but refers to a Circle?
A derived class that can be used wherever its more general type is expected has a relationship with that .
A class DetailedReport overrides BaseReport.Format(), while HiddenReport hides the same method with new. Which statement correctly distinguishes the two designs?
- A
The derived method is always ignored.
- B
The compiler rejects every call through the base type.
- C
A base-class reference can still reach the derived implementation.
- D
The new keyword guarantees run-time dispatch.
Which benefits follow from programming against an abstraction such as IPaymentProcessor? Select all that apply.
- A
Implementations can change without requiring changes to clients.
- B
Tests can provide fake or mock implementations.
- C
The caller must know the concrete class used at run time.
- D
New implementations can be added without modifying the caller.
An interface-based relationship requires all implementing classes to share a common implementation of their operations.
- A
True
- B
False
What design approach lets a Report contain an IFormatter and delegate rendering to it instead of inheriting from separate formatter-specific report classes?
The ability to replace a general type with a more specific type without breaking clients is called . It requires preserving the abstraction's .
Which situation best illustrates duck typing?
- A
The object must inherit from a specified base class.
- B
The object is accepted if it provides the required behavior.
- C
The compiler must generate a separate interface for every object.
- D
Only objects with identical fields can be substituted.
Which checks belong to a practical review of whether a subtype is safely substitutable? Select all that apply.
- A
It can be passed wherever the supertype is expected.
- B
It honors the supertype's preconditions and postconditions.
- C
It may impose stronger requirements if its method signatures match.
- D
It preserves important invariants of the abstraction.
Explain how programming against abstractions supports changeability and testability. Use the payment-processor example or an equivalent design, and explain why substitutability still matters.
Which guideline correctly distinguishes when inheritance or composition should be used?
- A
Inheritance should be used whenever it avoids duplicated helper methods.
- B
Composition is appropriate only when no interfaces exist.
- C
Inheritance should express a genuine subtype relationship, while composition suits a “has a” relationship.
- D
Composition prevents objects from using polymorphic behavior.
Which description best captures the central value of polymorphism?
- A
It requires every concrete type to use identical internal code.
- B
It allows different concrete types to be used through a common abstraction with specialized behavior.
- C
It means a caller must know the exact concrete class before invoking any operation.
- D
It replaces all interfaces with static utility methods.
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.
- A
True
- B
False
Given Shape shape = new Circle(2);, which implementation is selected when shape.Area() is invoked, assuming Area() is overridden?
- A
The call is rejected because Shape has no concrete implementation.
- B
The call always executes Shape.Area() because Shape is the declared type.
- C
The call executes Circle.Area() because Circle is the run-time type.
- D
The call selects an overload based on the constructor expression.
What type relationship describes a class that promises to provide the operations specified by an interface?
What is the important behavioral difference between using override and using new for a method in a derived C# class?
- A
overridepreserves dynamic dispatch through a base-class reference, whereasnewhides the member. - B
newpreserves dynamic dispatch, whereasoverridemakes the method private. - C
overrideandnewalways produce identical behavior through a base-class reference. - D
newcan be used only with abstract members, whereasoverridecan be used only with nonvirtual members.
A function accepts values through a base abstraction. Which condition is necessary for a new subtype to be safely substitutable?
- A
A subtype must expose more public methods than its supertype.
- B
A subtype may reject inputs that the supertype accepts if its implementation is more specialized.
- C
A subtype is substitutable whenever it inherits the same method names.
- D
A subtype must preserve the supertype's behavioral expectations when used through the abstraction.
What design approach lets an object delegate work to contained objects that implement an abstraction?
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.