Skills101
← All practice quizzes

Quiz: Inheritance and Virtual Functions

5 questionsNo time limitPass: 60%+10 XP on first pass

Reuse classes with inheritance, access modes, constructor order, virtual functions and the vtable, pure virtual functions and abstract classes, and why destructors must be virtual.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What makes a C++ class abstract?

  2. Question 2

    What does this print?

    #include <iostream>
    using namespace std;
    struct A { virtual void hi() { cout << "A"; } virtual ~A() = default; };
    struct B : A { void hi() override { cout << "B"; } };
    int main() {
        A *p = new B();
        p->hi();
        delete p;
        return 0;
    }
    
  3. Question 3

    In what order do constructors run for a Derived object?

  4. Question 4

    Why should a polymorphic base class have a virtual destructor?

  5. Question 5

    What does the override keyword do?