C++ Interview Questions

Bjarne-stroustrup
 
Prev7 of 17Next

According to the C++11 standard, what is the output of this program?

#include <iostream>

class A {
public:
	void f() { std::cout << "A"; }
};

class B : public A {
public:
	void f() { std::cout << "B"; }
};

void g(A &a) { a.f(); }

int main() {
	B b;
	g(b);
}

Answer