Skip to content
Quiz · Classes and OOP · lesson 10 of 13

Quiz — what override checks

What happens when you build and run this program?

C++
#include <iostream>

struct Base {
    virtual void print(int x) const { std::cout << "Base " << x; }
};
struct Derived : public Base {
    void print(long x) const override { std::cout << "Derived " << x; }
};

int main() { Derived d; const Base& b = d; b.print(1); }