ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
struct A { A() { cout << "A"; } };
struct B : virtual A { B() { cout << "B"; } };
struct C : virtual A { C() { cout << "C"; } };
struct D : B, C { D() { cout << "D"; } };
int main() { D d; }- A. ABACD
- B. DCBA
- C. ABCD
- D. BCAD
Correct answer: C. ABCD
With virtual inheritance D contains one shared A, constructed first by the most-derived class, then the bases in declaration order B, C, then D: ABCD. Without virtual each path would build its own A: ABACD.
More OOP with C++ and Java questions
- How many of these statements about C++ friend functions are correct? (i) A friend function can access the private members of the class…
- Interfaces A and B both declare default void hello(). What happens with class C implements A, B { } ?
- How many of these are correct in Java (8 or later)? (i) An abstract class can have a constructor. (ii) An interface can declare instance…
- What is printed? java // static methods of the main class: static void f() { try { System.out.print("1"); throw new…
- What is printed? java String s1 = "Java"; String s2 = "Ja" + "va"; String part = "Ja"; String s3 = part + "va"; System.out.print((s1 ==…
- What is printed? java class P { private void f() { System.out.print("P"); } void g() { f(); } } class C extends P { void f() {…