Polymorphism Class in Object Oriented Programming (OOPs) MCQ Questions and Answers
1. Which of the following best describes polymorphism in OOP?
A) A design pattern for UI components
B) The ability of a function to access private data
C) The ability of different objects to be treated through a common interface
D) A mechanism to prevent subclassing
Answer: C — The ability of different objects to be treated through a common interface
2. Which form of polymorphism is achieved by method overloading?
A) Subtype polymorphism
B) Ad-hoc (compile-time) polymorphism
C) Parametric polymorphism
D) Dynamic (run-time) polymorphism
Answer: B — Ad-hoc (compile-time) polymorphism
3. Which mechanism provides runtime polymorphism in languages like Java and C++?
A) Templates
B) Operator overloading
C) Method overriding with dynamic dispatch (virtual functions)
D) Function pointers only
Answer: C — Method overriding with dynamic dispatch (virtual functions)
4. Which term refers to the substitution of a derived class object where a base class object is expected?
A) Aggregation
B) Encapsulation
C) Liskov Substitution (principle supporting subtype polymorphism)
D) Reflection
Answer: C — Liskov Substitution (principle supporting subtype polymorphism)
5. Which is NOT a type of polymorphism usually discussed in OOP?
A) Ad-hoc polymorphism
B) Parametric polymorphism
C) Subtype polymorphism
D) Transmutational polymorphism
Answer: D — Transmutational polymorphism
6. Method overriding requires which of the following?
A) Same method name but different return type only
B) Different class name and same signature
C) Same method signature in subclass as in superclass
D) Only static methods
Answer: C — Same method signature in subclass as in superclass
7. Which one enables compile-time selection of which method to call?
A) Virtual functions
B) Reflection
C) Method overloading
D) Dynamic casting
Answer: C — Method overloading
8. In C++, which keyword is used to enable runtime polymorphism by marking a base method?
A) override
B) final
C) friend
D) virtual
Answer: D — virtual
9. What is the role of a vtable in supporting polymorphism?
A) It enforces access control
B) It stores variable values only
C) It maps virtual functions to their runtime implementations
D) It replaces the program stack
Answer: C — It maps virtual functions to their runtime implementations
10. Parametric polymorphism is commonly implemented via:
A) Method overriding
B) Virtual tables
C) Generics or templates
D) Function pointers
Answer: C — Generics or templates
11. Which of these is an example of ad-hoc polymorphism?
A) Subclassing interfaces
B) Virtual inheritance
C) Function overloading
D) Template specialization
Answer: C — Function overloading
12. Which polymorphism type allows one function to operate on arguments of different types using the same interface without rewriting code?
A) Ad-hoc polymorphism only
B) Parametric polymorphism
C) Subtype polymorphism only
D) None of the above
Answer: B — Parametric polymorphism
13. Covariant return types allow:
A) Changing parameter types in overridden methods
B) Converting instance variables type at runtime
C) A subclass method to return a more specific type than the base method
D) Overloading constructors only
Answer: C — A subclass method to return a more specific type than the base method
14. What happens if a derived class in Java does not override a base class method that is called via a base reference pointing to a derived object?
A) Compile-time error
B) Program crashes
C) Base class’s method executes (unless overridden)
D) The JVM asks for user input
Answer: C — Base class’s method executes (unless overridden)
15. Which statement about static methods and polymorphism is true?
A) Static methods are always virtual
B) Static methods support overriding per instance
C) Static methods are not polymorphic (they are bound at compile time)
D) Static methods are the only polymorphic methods in Java
Answer: C — Static methods are not polymorphic (they are bound at compile time)
16. In a polymorphic call, late binding refers to:
A) Selecting the variable type at compile time
B) Resolving the method implementation at runtime
C) Combining two unrelated classes’ methods
D) Overloading a method with multiple signatures
Answer: B — Resolving the method implementation at runtime
17. Which of the following best describes subtype polymorphism?
A) Multiple function definitions with different parameter types
B) Objects of subclasses being usable where base class objects are expected
C) Generic code parameterized by types
D) Compile-time function selection by signature
Answer: B — Objects of subclasses being usable where base class objects are expected
18. Operator overloading is an example of which kind of polymorphism?
A) Subtype polymorphism
B) Parametric polymorphism
C) Ad-hoc polymorphism
D) Inclusion polymorphism
Answer: C — Ad-hoc polymorphism
19. Which of the following is a necessary condition for method overriding in Java?
A) Methods must be static
B) Methods must be private
C) Method names and parameter lists must be identical
D) Return types must be unrelated
Answer: C — Method names and parameter lists must be identical
20. Which OOP principle is most directly related to polymorphism?
A) Encapsulation only
B) Inheritance (for subtype polymorphism) and interfaces
C) File I/O
D) Multithreading
Answer: B — Inheritance (for subtype polymorphism) and interfaces
21. What does “dynamic dispatch” mean?
A) Dispatching messages to different threads
B) Selecting which implementation of an overridden method to execute at runtime
C) Ordering network packets dynamically
D) Generating code at compile time
Answer: B — Selecting which implementation of an overridden method to execute at runtime
22. Which language feature typically prevents runtime polymorphism from working on a method?
A) Declaring method as protected
B) Declaring method as abstract
C) Declaring method as final (or sealed)
D) Declaring method as virtual
Answer: C — Declaring method as final (or sealed)
23. In Java, which construct allows polymorphism without inheritance?
A) Abstract classes only
B) Final classes
C) Interfaces
D) Static nested classes
Answer: C — Interfaces
24. Which is true about interface-based polymorphism?
A) It requires sharing instance variables
B) It cannot be used in statically typed languages
C) It allows unrelated classes to share a common contract
D) It is the same as method overloading
Answer: C — It allows unrelated classes to share a common contract
25. What is object slicing in C++?
A) A technique for optimizing memory
B) Assigning derived objects to pointers
C) Truncation of the derived part when assigning a derived object to a base object by value
D) Overriding a method in derived class
Answer: C — Truncation of the derived part when assigning a derived object to a base object by value
26. Which of the following best protects against object slicing in C++?
A) Using static functions
B) Passing objects by value always
C) Using pointers or references to base class (and virtual destructor)
D) Declaring classes as final
Answer: C — Using pointers or references to base class (and virtual destructor)
27. In C++, why should a base class have a virtual destructor when used polymorphically?
A) To prevent compiler warnings only
B) To speed up destruction
C) To ensure derived class destructors are called when deleting via base pointer
D) To allow multiple inheritance
Answer: C — To ensure derived class destructors are called when deleting via base pointer
28. Which of these is NOT an advantage of polymorphism?
A) Code reusability
B) Flexibility and maintainability
C) Easier unit testing for isolated behavior
D) Guaranteed performance improvement
Answer: D — Guaranteed performance improvement
29. Which of the following statements is true about method overloading and overriding?
A) Overloading is runtime, overriding is compile-time
B) Overloading requires inheritance, overriding does not
C) Overloading is compile-time polymorphism; overriding is runtime polymorphism
D) Both are identical concepts
Answer: C — Overloading is compile-time polymorphism; overriding is runtime polymorphism
30. Which polymorphism concept allows a single function to work on objects of different classes that implement the same interface?
A) Ad-hoc polymorphism
B) Parametric polymorphism
C) Subtype polymorphism (interface-based polymorphism)
D) Compile-time binding
Answer: C — Subtype polymorphism (interface-based polymorphism)
31. In Java, which keyword indicates a method must be overridden by subclasses?
A) final
B) static
C) abstract
D) synchronized
Answer: C — abstract
32. Which of the following is necessary for method dispatch via virtual functions?
A) Compile-time templates
B) Static linking
C) A runtime mechanism (like vtable) or equivalent
D) Overloaded constructors
Answer: C — A runtime mechanism (like vtable) or equivalent
33. The principle “program to an interface, not an implementation” primarily promotes:
A) Tighter coupling
B) More code duplication
C) Loose coupling and polymorphism
D) Prevention of inheritance
Answer: C — Loose coupling and polymorphism
34. Which of the following describes parametric polymorphism?
A) Methods change signature dynamically
B) Writing code that works uniformly for any type parameter (e.g., Java generics)
C) Only supports numeric types
D) Is limited to C++ virtual functions
Answer: B — Writing code that works uniformly for any type parameter (e.g., Java generics)
35. Which is a limitation of runtime polymorphism?
A) It is always faster than compile-time selection
B) It can incur a performance overhead due to dynamic dispatch
C) It prevents code reuse
D) It requires templates
Answer: B — It can incur a performance overhead due to dynamic dispatch
36. Which of the following supports polymorphism across unrelated classes?
A) Class inheritance only
B) Protected members only
C) Interfaces (or protocols in some languages)
D) Friend declarations
Answer: C — Interfaces (or protocols in some languages)
37. In a language with multiple dispatch, method selection is based on:
A) Only the static type of the caller
B) Only the return type
C) Runtime types of multiple arguments
D) The file name
Answer: C — Runtime types of multiple arguments
38. Which term describes polymorphism achieved by coercion or implicit type conversion?
A) Parametric polymorphism
B) Ad-hoc polymorphism via coercion
C) Subtype polymorphism
D) Structural polymorphism
Answer: B — Ad-hoc polymorphism via coercion
39. Which of the following is true about virtual functions in C++?
A) They must be static
B) They cannot be overridden
C) They enable dynamic binding when called through base pointers/references
D) They do not support inheritance
Answer: C — They enable dynamic binding when called through base pointers/references
40. What is structural polymorphism?
A) Polymorphism based on inheritance hierarchy names
B) Polymorphism based on an object’s structure/signature (duck typing)
C) Polymorphism requiring explicit interfaces only
D) Same as operator overloading
Answer: B — Polymorphism based on an object’s structure/signature (duck typing)
41. Which practice helps write polymorphic code that is easy to extend?
A) Hard-coding class names in methods
B) Using many global variables
C) Rely on interfaces/abstract base classes and dependency injection
D) Avoiding modularization
Answer: C — Rely on interfaces/abstract base classes and dependency injection
42. What is the difference between interface and abstract class in context of polymorphism?
A) Interfaces can’t be used for polymorphism
B) Abstract classes can have implemented behavior; interfaces declare contracts (language dependent)
C) Abstract classes are only for data, not behavior
D) They are always identical in all languages
Answer: B — Abstract classes can have implemented behavior; interfaces declare contracts (language dependent)
43. Which of the following is true about virtual function tables (vtables)?
A) They are unique to Java only
B) They store object data directly
C) They are used by compilers to implement dynamic dispatch
D) They are the same as the call stack
Answer: C — They are used by compilers to implement dynamic dispatch
44. Which is an example of inclusion polymorphism?
A) Function templates with type parameters
B) Using a derived class instance through a base class reference
C) Method overloading by return type
D) Implicit type conversion only
Answer: B — Using a derived class instance through a base class reference
45. Which statement about interfaces and polymorphism in Java 8+ is accurate?
A) Interfaces cannot contain any methods with bodies
B) Interfaces cannot be used for polymorphism
C) Interfaces may contain default methods and still support polymorphism
D) Interfaces must be final
Answer: C — Interfaces may contain default methods and still support polymorphism
46. Which term fits the following definition: “a method whose behavior depends on the runtime type of the object it is invoked on”?
A) Generic method
B) Inline method
C) Virtual (overridden) method
D) Static method
Answer: C — Virtual (overridden) method
47. In languages with single dispatch (like Java), method selection is primarily based on:
A) The static types of all arguments
B) The return type only
C) The runtime type of the receiver (object) and static types of arguments
D) The file path and function name
Answer: C — The runtime type of the receiver (object) and static types of arguments
48. Which of these describes compile-time (static) binding?
A) Decisions are made during execution only
B) It cannot be optimized by the compiler
C) Method calls are resolved at compile time (e.g., overloaded methods)
D) It requires a vtable
Answer: C — Method calls are resolved at compile time (e.g., overloaded methods)
49. Which is a correct reason to declare a method final in Java with respect to polymorphism?
A) To allow more overriding
B) To enable dynamic dispatch only
C) To prevent subclasses from overriding that method
D) To free memory at runtime
Answer: C — To prevent subclasses from overriding that method
50. Which OOP feature is most closely tied to polymorphism and encapsulation working together?
A) Multithreading synchronization
B) Interfaces/abstract base classes encapsulating behavior while polymorphism provides interchangeability
C) Low-level pointer arithmetic
D) Global variables for state management
Answer: B — Interfaces/abstract base classes encapsulating behavior while polymorphism provides interchangeability
51. Which of the following statements about method signatures and overriding is true in Java?
A) Two methods with the same name but different return types can override each other
B) Return types must be compatible (covariant allowed) when overriding
C) Overriding requires different parameter lists
D) Private methods in superclass are always overridden publicly
Answer: B — Return types must be compatible (covariant allowed) when overriding
52. What is the typical effect of polymorphism on code coupling?
A) It always increases coupling
B) It reduces coupling by allowing code to depend on abstractions
C) It eliminates the need for modularization
D) It has no effect on coupling
Answer: B — It reduces coupling by allowing code to depend on abstractions
53. Which idiom is commonly paired with polymorphism to select concrete implementations at runtime?
A) Singleton only
B) Using static methods
C) Factory pattern or dependency injection
D) Inline assembly
Answer: C — Factory pattern or dependency injection
54. Which of these statements about virtual inheritance (C++) and polymorphism is true?
A) Virtual inheritance is unrelated to polymorphism
B) Virtual inheritance prevents polymorphism entirely
C) Virtual inheritance resolves the diamond problem and affects object layout used in polymorphism
D) Virtual inheritance only applies to Java
Answer: C — Virtual inheritance resolves the diamond problem and affects object layout used in polymorphism
55. Which term describes when different types provide the same method name and signature, and the caller does not care about concrete type?
A) Name mangling
B) Static typing only
C) Polymorphism (uniform interface)
D) Dead code elimination
Answer: C — Polymorphism (uniform interface)
56. Why might a language designer choose to disallow overriding of certain methods?
A) To reduce code readability
B) To prevent polymorphism entirely
C) To preserve invariants or essential behavior of the base class
D) To make the code mutable only
Answer: C — To preserve invariants or essential behavior of the base class
57. Which of the following is true about method dispatch tables in multiple-inheritance schemes?
A) They are unnecessary
B) They always match single inheritance exactly
C) They may be more complex to handle offsets and multiple vtables
D) They are stored in source code comments
Answer: C — They may be more complex to handle offsets and multiple vtables
58. Structural typing (as in some languages) differs from nominal typing in that:
A) Structural typing requires explicit inheritance declarations
B) Structural typing bases compatibility on an object’s shape rather than explicit declarations
C) Nominal typing is faster in all cases
D) Structural typing prevents polymorphism
Answer: B — Structural typing bases compatibility on an object’s shape rather than explicit declarations
59. Which of the following is a safe way to downcast in C++ when using polymorphism?
A) C-style cast always
B) reinterpret_cast on pointers
C) dynamic_cast with RTTI (when casting across polymorphic hierarchies)
D) static_cast without checks always
Answer: C — dynamic_cast with RTTI (when casting across polymorphic hierarchies)
60. What is the relationship between polymorphism and extensibility?
A) Polymorphism reduces extensibility
B) They are unrelated concepts
C) Polymorphism increases extensibility by allowing new types to be integrated without modifying clients
D) Extensibility prevents polymorphism from working
Answer: C — Polymorphism increases extensibility by allowing new types to be integrated without modifying clients
61. Which of these is an example of parametric polymorphism in Java?
A) Overriding equals() method
B) Using List<T> where T is a type parameter
C) Declaring methods final
D) Using private constructors only
Answer: B — Using List<T> where T is a type parameter
62. In languages with duck typing, polymorphism is primarily achieved by:
A) Using vtables only
B) Explicit interface declarations
C) Objects providing methods with expected names and signatures (“if it quacks”)
D) Compile-time template instantiation
Answer: C — Objects providing methods with expected names and signatures (“if it quacks”)
63. Which of the following would break polymorphism when assigning a subclass object to a base class variable?
A) Assigning by pointer or reference
B) Declaring the base method virtual
C) Slicing (assigning by value to base object)
D) Using interfaces for contracts
Answer: C — Slicing (assigning by value to base object)
64. Which of the following is true about generic types and polymorphism?
A) Generics replace runtime polymorphism completely
B) Generics provide compile-time type safety for code that can operate on multiple types
C) Generics are only useful for primitives
D) Generics force dynamic binding always
Answer: B — Generics provide compile-time type safety for code that can operate on multiple types
65. Which is a common testing advantage provided by polymorphism?
A) Tests must know concrete classes at all times
B) Ability to use mock implementations that conform to the same interface
C) It prevents mocking entirely
D) Polymorphism slows unit tests drastically
Answer: B — Ability to use mock implementations that conform to the same interface
66. Which of these is NOT a correct statement about virtual methods?
A) Virtual methods can be overridden by derived classes
B) Virtual methods support polymorphism when accessed via base pointers/references
C) Virtual methods are resolved at compile time
D) Virtual methods often use a vtable internally
Answer: C — Virtual methods are resolved at compile time
67. The adapter pattern often leverages polymorphism primarily to:
A) Increase the number of classes to maintain
B) Allow existing classes to present a compatible interface to clients
C) Avoid any use of interfaces
D) Remove inheritance entirely
Answer: B — Allow existing classes to present a compatible interface to clients
68. Which of these is true about abstract classes and polymorphism?
A) Abstract classes cannot provide any method implementations
B) Abstract classes can define default behavior and abstract methods that subclasses must implement
C) Abstract classes force callers to know concrete types
D) Abstract classes are always instantiated directly
Answer: B — Abstract classes can define default behavior and abstract methods that subclasses must implement
69. Which of the following is a risk of excessive polymorphism usage?
A) It ensures perfect performance always
B) It eliminates the need for tests
C) It can lead to complex class hierarchies and harder-to-understand code
D) It prevents code reusability
Answer: C — It can lead to complex class hierarchies and harder-to-understand code
70. What is the main difference between overloading and overriding?
A) Overriding changes method name, overloading does not
B) Overloading is same-scope multiple signatures; overriding is subclass redefinition of same signature
C) Overloading is runtime only; overriding is compile-time only
D) There is no difference
Answer: B — Overloading is same-scope multiple signatures; overriding is subclass redefinition of same signature
71. Which of the following best explains why virtual functions slightly increase object size in many implementations?
A) Virtual functions store all variables inline
B) Virtual functions require duplicate objects
C) Objects often contain a hidden pointer to a vtable (vptr)
D) Virtual functions add metadata to source code only
Answer: C — Objects often contain a hidden pointer to a vtable (vptr)
72. Which statement is correct about polymorphism and design patterns?
A) Polymorphism is rarely used in design patterns
B) Many design patterns (Strategy, Command, State) use polymorphism to vary behavior
C) Patterns always avoid polymorphism for performance reasons
D) Polymorphism defeats pattern usage
Answer: B — Many design patterns (Strategy, Command, State) use polymorphism to vary behavior
73. Which concept allows different objects to be printed using the same print function, each showing its own format?
A) Static binding
B) Overloading only
C) Polymorphism via overriding (e.g., toString()/str methods)
D) Using global functions only
Answer: C — Polymorphism via overriding (e.g., toString()/str methods)
74. What is the significance of an “interface segregation” in relation to polymorphism?
A) It forces everything into one huge interface
B) It removes polymorphism abilities
C) It advises many small, focused interfaces to improve polymorphism and maintainability
D) It is unrelated to interfaces
Answer: C — It advises many small, focused interfaces to improve polymorphism and maintainability
75. Which of the following is true in languages where functions are first-class and used for polymorphism?
A) Functions cannot be passed as arguments
B) Behavior can be passed and composed at runtime enabling polymorphic behavior
C) Functions cannot implement interfaces
D) First-class functions prevent polymorphism
Answer: B — Behavior can be passed and composed at runtime enabling polymorphic behavior
76. Which of the following is an example of runtime polymorphism in Java?
A) Method overloading based on parameter types
B) Calling an overridden method on a base reference that refers to a subclass object
C) Using generics with type parameters only
D) Using final methods only
Answer: B — Calling an overridden method on a base reference that refers to a subclass object
77. Which is true about default methods in Java interfaces with respect to polymorphism?
A) Default methods prevent classes from implementing the interface
B) Default methods provide a default implementation used unless overridden, still supporting polymorphism
C) Default methods are always static and cannot be overridden
D) Default methods make the interface abstract ineligible for polymorphism
Answer: B — Default methods provide a default implementation used unless overridden, still supporting polymorphism
78. What is the name for a polymorphism type where functions behave differently based on the number or type of parameters?
A) Parametric polymorphism only
B) Ad-hoc polymorphism (overloading)
C) Subtype polymorphism only
D) Inheritance polymorphism only
Answer: B — Ad-hoc polymorphism (overloading)
79. Which of the following ensures type safety while providing polymorphic behavior at compile time?
A) Using raw void pointers only
B) Ignoring type checks
C) Generics/templates with static type checks
D) Runtime string-based dispatch only
Answer: C — Generics/templates with static type checks
80. Which of these is NOT commonly required for runtime subtype polymorphism?
A) Base class reference/pointer
B) Overridden methods in subclass
C) Compile-time templates
D) Mechanism for dynamic dispatch
Answer: C — Compile-time templates
81. Which is typically the best practice for a base class used polymorphically?
A) Make destructor non-virtual in C++
B) Provide a virtual destructor (in C++), define public/protected virtual methods
C) Prevent all methods from being overridden
D) Avoid any abstraction
Answer: B — Provide a virtual destructor (in C++), define public/protected virtual methods
82. Which statement about polymorphism and interfaces is correct?
A) Interfaces limit polymorphism to single inheritance only
B) Interfaces allow multiple types to be used interchangeably by defining a common contract
C) Interfaces require objects to be of same concrete class
D) Interfaces are only useful for static typing
Answer: B — Interfaces allow multiple types to be used interchangeably by defining a common contract
83. Which of the following tools helps detect incorrect casts at runtime when using polymorphism in C++?
A) static_cast without checks
B) reinterpret_cast only
C) dynamic_cast (requires RTTI)
D) C-style cast always safe
Answer: C — dynamic_cast (requires RTTI)
84. Which of the following design goals is directly supported by polymorphism?
A) Hard-coded control flow
B) Eliminating abstraction layers
C) Open/Closed Principle: open for extension, closed for modification
D) Ignoring interfaces
Answer: C — Open/Closed Principle: open for extension, closed for modification
85. Which one is a common pattern to handle polymorphism across processes or systems (not just in-memory objects)?
A) Using inline functions only
B) Direct pointer casting across processes
C) Using interfaces or message formats (RPC/serialization) that map to polymorphic types
D) Avoiding any abstraction between systems
Answer: C — Using interfaces or message formats (RPC/serialization) that map to polymorphic types
86. Which of the following about operator overloading and polymorphism is correct?
A) Operator overloading never relates to polymorphism
B) Operator overloading is a form of ad-hoc polymorphism
C) Overloaded operators cannot be overloaded for custom classes
D) Operator overloading is always runtime polymorphism
Answer: B — Operator overloading is a form of ad-hoc polymorphism
87. Which is a correct effect of using polymorphism on software maintenance?
A) It eliminates all future bugs
B) It makes adding new implementations harder always
C) It usually simplifies adding new implementations without changing client code
D) It prevents unit testing
Answer: C — It usually simplifies adding new implementations without changing client code
88. Which of the following best describes bounded parametric polymorphism?
A) Generics with no restrictions
B) Generic type parameters that are constrained to a specific interface or superclass
C) Templates that expand at runtime only
D) Implicit casts between unrelated types
Answer: B — Generic type parameters that are constrained to a specific interface or superclass
89. Which of the following enables a function to accept any object that implements a particular method signature without explicit type ties (in dynamic languages)?
A) Virtual tables exclusively
B) static typing strictly enforced
C) Duck typing (structural polymorphism)
D) Only inheritance-based dispatch
Answer: C — Duck typing (structural polymorphism)
90. Which of these is often necessary for polymorphic serialization/deserialization of objects?
A) Using plain text only
B) Avoiding type identifiers in serialized data
C) Including type metadata or class identifiers to reconstruct correct concrete type
D) Only serializing base class fields always
Answer: C — Including type metadata or class identifiers to reconstruct correct concrete type
91. Which of the following demonstrates polymorphism via composition rather than inheritance?
A) Extending a base class only
B) Holding a strategy object and delegating calls to it (Strategy pattern)
C) Overriding base class final methods
D) Using operator overloading only
Answer: B — Holding a strategy object and delegating calls to it (Strategy pattern)
92. In the context of polymorphism, what is a “dispatch” table primarily used for?
A) Storing instance variables exclusively
B) Sorting a list of functions at compile time
C) Mapping method identifiers to concrete function pointers for the object’s type
D) Replacing function arguments with constants
Answer: C — Mapping method identifiers to concrete function pointers for the object’s type
93. Which of the following is true about sealed classes (or final classes) and polymorphism?
A) Sealed classes encourage subclassing to increase polymorphism
B) They always enable more polymorphic behavior
C) Sealed/final classes prevent further subclassing, limiting subtype polymorphism
D) Sealed classes automatically generate interfaces
Answer: C — Sealed/final classes prevent further subclassing, limiting subtype polymorphism
94. Which of these is an example of structural polymorphism in statically typed languages?
A) Using vtables exclusively
B) Implicit conversions across unrelated types only
C) Type inference that accepts any object having required members (as in Go interfaces)
D) Declaring methods final only
Answer: C — Type inference that accepts any object having required members (as in Go interfaces)
95. Which concept is used to bind a method call to its definition at runtime?
A) Inline expansion at compile time
B) Name mangling only
C) Late binding (dynamic binding)
D) Static memory allocation
Answer: C — Late binding (dynamic binding)
96. Which of the following is true about polymorphism and caching method results?
A) Polymorphism always prevents caching
B) Caching is unaffected by virtual dispatch always
C) Caching must consider dynamic dispatch—results valid per concrete type/behavior
D) Caching can be done by ignoring runtime type differences safely
Answer: C — Caching must consider dynamic dispatch—results valid per concrete type/behavior
97. Which of the following terms best describes a function that works with any object having a certain method without needing a common base class?
A) Nominally typed function only
B) Duck-typed function (structural polymorphism)
C) Finalized function only
D) Static-only function
Answer: B — Duck-typed function (structural polymorphism)
98. Which of the following is commonly used to avoid breaking polymorphism when extending an API?
A) Changing method signatures frequently
B) Removing interfaces abruptly
C) Adding new implementations while keeping existing contracts intact (maintain backward compatibility)
D) Making all classes final always
Answer: C — Adding new implementations while keeping existing contracts intact (maintain backward compatibility)
99. Which of the following accurately compares templates (C++) and virtual functions for polymorphism?
A) Templates provide runtime polymorphism only
B) Virtual functions provide compile-time polymorphism only
C) Templates provide compile-time (parametric) polymorphism; virtual functions provide runtime (subtype) polymorphism
D) They are the exact same mechanism
Answer: C — Templates provide compile-time (parametric) polymorphism; virtual functions provide runtime (subtype) polymorphism
100. Which of the following best describes the use of polymorphism in testing?
A) It prevents using test doubles
B) It requires concrete classes for tests always
C) It facilitates using mock or stub implementations conforming to the same interface for isolation
D) It forces tests to use production databases only
Answer: C — It facilitates using mock or stub implementations conforming to the same interface for isolation
