All challenges
Multiple ChoiceBeginner 45s

Default argument vs virtual dispatch

A base and derived both define `f(int x = 1)` and `f(int x = 2)` as virtual. Calling via `Base* b = new Derived; b->f();` uses:
Options
  1. 1Both the default argument and the function body are taken from Derived, since it is the dynamic type.
  2. 2The default argument from the static type (Base, so 1) but the function body from the dynamic type (Derived).
  3. 3Both the default argument and the function body are taken from Base, since it is the static type.
  4. 4A compile error, because default arguments are not permitted to appear on a virtual function declaration.

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle