Polymorphism Made Simple: Compile-Time vs Runtime Quiz

  1. Q1. What is polymorphism?

    Which statement best describes polymorphism in object-oriented programming?

    1. The ability of a single interface or function name to represent different underlying forms or behaviors
    2. Encapsulation (hiding data fields from outside access)
    3. Inheritance (sharing structure from a base class)
    4. Polyglotism (writing programs in many human languages)
    5. Polymorfism (misspelled term)
  2. Q2. Identify compile-time polymorphism

    Which of the following is a common example of compile-time polymorphism?

    1. Method overloading resolved by parameter types at compile time
    2. Method overriding chosen based on object type at runtime
    3. Dynamic dispatch via virtual methods
    4. Late binding of method calls
    5. Reflection-based invocation of methods
  3. 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?

    1. Runtime polymorphism (dynamic dispatch)
    2. Compile-time polymorphism (overloading)
    3. Macro expansion
    4. Inline substitution decided by the compiler
    5. Early bindng determined by declared type
  4. 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()?

    1. Dynamic dispatch at runtime
    2. Function overloading resolution
    3. Static binding
    4. Name mangling
    5. Type erasion
  5. Q5. Overloading rules

    Which statement about method overloading is true in typical statically typed object-oriented languages?

    1. Overloading requires methods with the same name but different parameter lists; return type alone is not enough
    2. Overloading requires methods to be in different classes only
    3. Overloading decides which method to call based on the actual object type at runtime
    4. Overloading allows changing only the return type while keeping parameters identical
    5. Overloading works only with virtual methods
  6. Q6. Overriding rules

    Which statement about method overriding is correct when a subclass provides its own implementation of a base method?

    1. Overriding requires the subclass method to match the parent's signature and be compatible in return type
    2. Overriding is selected purely by parameter count and types at compile time
    3. Private methods in a base class are commonly overridden in subclasses
    4. Static methods are overridden to enable dynamic dispatch
    5. Overridding lets you change only default arguments without changing behavior
  7. Q7. Benefit of runtime polymorphism

    Which scenario best illustrates the benefit of runtime polymorphism?

    1. A function processes a collection of Shape references and calls area(), and each specific shape's area() is invoked
    2. A program chooses between two overloaded print() methods at compile time based on whether an int or a string is passed
    3. A macro expands into different code before compilation
    4. A constant is inlined into the code by the compiler
    5. A function template generates separate functions for int and double
  8. Q8. Operator overloading category

    In languages that support it, what category of polymorphism does operator overloading typically exemplify?

    1. Compile-time polymorphism (ad hoc polymorphism)
    2. Runtime polymorphism via virtual methods
    3. Duck typing resolved at runtime
    4. Late binding through reflection
    5. Procedural abstraction without polymorphism
  9. 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();?

    1. The static method associated with the reference's declared type is chosen at compile time (Base.greet())
    2. The static method in Derived is always chosen at runtime due to dynamic dispatch
    3. The static method call is ambiguous and causes a runtime error
    4. The compiler randomly picks one at build time
    5. Static methods participate in late bindng just like virtual methods
  10. Q10. Generics/templates classification

    Using a generic function or template that the compiler instantiates for each type argument primarily demonstrates which kind of polymorphism?

    1. Compile-time polymorphism (parametric polymorphism)
    2. Runtime polymorphism via overriding
    3. Structural typing decided at runtime
    4. Just-in-time reflection-based dispatch
    5. Dynamic casting polymorfism