🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Multiple Inheritance and the Diamond Problem: all 10 questions

Quiz: Multiple Inheritance and the Diamond Problem · Question 2 of 10

What does this print? (code)

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;
}
  1. A.ABCcba
  2. B.BACcab
  3. C.BACabc
  4. D.CABabc
Answer & explanation

Correct answer: BACcab

B is listed first, so B, A, then C are built; destruction is the reverse: c, a, b.

Can you get the rest right without peeking?

Take the timed Quiz: Multiple Inheritance and the Diamond Problem quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →