ProgrammingVery hardWipro Elite · TCS NQT Prime
What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)
What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)
struct A { A() { cout << "A"; } };
struct B { B() { cout << "B"; } };
struct C : B, A {
A a; B b;
C() { cout << "C"; }
};
int main() { C c; }- A. ABABC
- B. ABBAC
- C. CBAAB
- D. BAABC
Correct answer: D. BAABC
Bases are built in base-list order (B, A), then members in declaration order (a, b), then the body: B A A B C.
More OOP with C++ and Java questions
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct I { int v; I& operator++() { ++v…
- What is printed? (also assume <typeinfo>) (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct G { const char n; G(const char s)…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp struct A { virtual void f() { cout << "A"; }…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp void f(bool) { cout << "b"; } void f(string) {…
- What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std) cpp template <class T> void f(T) { cout << "T"; }…