What will be displayed as a result of the program execution?
#include <iostream>

using namespace std;

struct B
  void f() { cout << "B"; }

struct C: B
  void f() { cout << "C"; }

int main()
  C c;

  B *b1 = &c;

  B b2 = c;
  return 0;
Method B::f() is not a virtual method, so when you access it through the pointer to the object of the base class, this method is called, not the overridden method of the child class.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes