Skills101
← All practice quizzes

Quiz: Multiple Inheritance and the Diamond Problem

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

A C++ class can inherit from more than one base class. Learn constructor and destructor order, name ambiguity and how to resolve it, the diamond problem, virtual inheritance, and using multiple inheritance safely with interfaces.

Log in to take the quiz

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

  1. Question 1

    In class Copier : public Printer, public Scanner, which constructor runs first when a Copier is created?

  2. Question 2

    What does this print?

    #include <iostream>
    using namespace std;
    struct A { A() { cout << "A"; } ~A() { cout << "a"; } };
    struct B { B() { cout << "B"; } ~B() { cout << "b"; } };
    struct C : public B, public A { C() { cout << "C"; } ~C() { cout << "c"; } };
    int main() {
        C obj;
        return 0;
    }
    
  3. Question 3

    Both bases of a class define status(). What happens when you call obj.status() without overriding it?

  4. Question 4

    What is the diamond problem?

  5. Question 5

    Where is the virtual keyword written to fix the diamond Device → Printer/Scanner → Copier?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →