Multiple choice

What is the output of the following program?

#include <iostream> using namespace std;

class Base { public: void fun() { cout << “Base Class” << endl; } }; class Derived : public Base { public: void fun() { cout << “Derived Class” << endl; } }; int main() { Derived objD; Base *ptrB = &objD; ptrB->fun(); }

  1. Base Class

  2. Derived Class

  3. No output. A Compilation Error

  4. No output. A Runtime Error

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Compile time binding of a non-virtual function is based on the data type of the pointer.