← 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;
}
- A.ABCcba
- B.BACcab
- C.BACabc
- 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 →