Q1. What is polymorphism?
Which statement best describes polymorphism in object-oriented programming?
- The ability of a single interface or function name to represent different underlying forms or behaviors
- Encapsulation (hiding data fields from outside access)
- Inheritance (sharing structure from a base class)
- Polyglotism (writing programs in many human languages)
- Polymorfism (misspelled term)
Q2. Identify compile-time polymorphism
Which of the following is a common example of compile-time polymorphism?
- Method overloading resolved by parameter types at compile time
- Method overriding chosen based on object type at runtime
- Dynamic dispatch via virtual methods
- Late binding of method calls
- Reflection-based invocation of methods
Q3. Identify runtime polymorphism
If class Bird and subclass Sparrow both implement fly(), and a Bird reference holds a Sparrow object and calls fly(), which kind of polymorphism selects the implementation?
- Runtime polymorphism (dynamic dispatch)
- Compile-time polymorphism (overloading)
- Macro expansion
- Inline substitution decided by the compiler
- Early bindng determined by declared type
Q4. Dynamic dispatch in action
Given the code snippet Base b = new Derived(); b.draw(); which concept ensures that Derived.draw() is called instead of Base.draw()?
- Dynamic dispatch at runtime
- Function overloading resolution
- Static binding
- Name mangling
- Type erasion
Q5. Overloading rules
Which statement about method overloading is true in typical statically typed object-oriented languages?
- Overloading requires methods with the same name but different parameter lists; return type alone is not enough
- Overloading requires methods to be in different classes only
- Overloading decides which method to call based on the actual object type at runtime
- Overloading allows changing only the return type while keeping parameters identical
- Overloading works only with virtual methods
Q6. Overriding rules
Which statement about method overriding is correct when a subclass provides its own implementation of a base method?
- Overriding requires the subclass method to match the parent's signature and be compatible in return type
- Overriding is selected purely by parameter count and types at compile time
- Private methods in a base class are commonly overridden in subclasses
- Static methods are overridden to enable dynamic dispatch
- Overridding lets you change only default arguments without changing behavior
Q7. Benefit of runtime polymorphism
Which scenario best illustrates the benefit of runtime polymorphism?
- A function processes a collection of Shape references and calls area(), and each specific shape's area() is invoked
- A program chooses between two overloaded print() methods at compile time based on whether an int or a string is passed
- A macro expands into different code before compilation
- A constant is inlined into the code by the compiler
- A function template generates separate functions for int and double
Q8. Operator overloading category
In languages that support it, what category of polymorphism does operator overloading typically exemplify?
- Compile-time polymorphism (ad hoc polymorphism)
- Runtime polymorphism via virtual methods
- Duck typing resolved at runtime
- Late binding through reflection
- Procedural abstraction without polymorphism
Q9. Static methods and binding
If Base has a static method greet() and Derived declares a static method with the same name, what is true when you call greet() through a variable declared as Base b = new Derived();?
- The static method associated with the reference's declared type is chosen at compile time (Base.greet())
- The static method in Derived is always chosen at runtime due to dynamic dispatch
- The static method call is ambiguous and causes a runtime error
- The compiler randomly picks one at build time
- Static methods participate in late bindng just like virtual methods
Q10. Generics/templates classification
Using a generic function or template that the compiler instantiates for each type argument primarily demonstrates which kind of polymorphism?
- Compile-time polymorphism (parametric polymorphism)
- Runtime polymorphism via overriding
- Structural typing decided at runtime
- Just-in-time reflection-based dispatch
- Dynamic casting polymorfism