Multiple choice

What is the output of the following program?

Assume sizeof( int ) = 4

#include <iostream> using namespace std;

class Base { public: virtual void fun() { cout << “Base Class” << endl; } }; class Derived : public Base { public: void fun() { cout << “Derived Class” << endl; } }; int main() { Base objBase; cout << sizeof( objBase ) << endl; }

  1. 0

  2. 1

  3. 4

  4. 8

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

An invisible virtual pointer is automatically inserted in a class when at least one of its methods is declared as virtual. The size of a pointer is 4 bytes.