-
What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
virtual void print() const = 0;
};
class DerivedClassOne : public BaseClass
{
public:
void print() const
{
cout << "Derived class One\n";
}
};
class DerivedClassTwo : public BaseClass
{
public:
void print() const
{
cout << "Derived class Two\n";
}
};
class MultipleClass : public DerivedClassOne, public DerivedClassTwo
{
public:
void print() const
{
DerivedClassTwo :: print();
}
};
int main()
{
int i;
MultipleClass both;
DerivedClassOne one;
DerivedClassTwo two;
BaseClass *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &one;
array[ 2 ] = &two;
array[ i ] -> print();
return 0;
}
-
- Derived class Two
- Derived class One
- Compilation Error
- Runtime Error
- None of these
Correct Option: C
In this program, ‘BaseClass’ is an ambiguous base of ‘MultipleClass’. So it is producing an error. And this program is a virtual base class.