1.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
virtual void print() const = 0;
};
class DerivedClassA : virtual public BaseClass
{
public:
void print() const
{
cout << " 5 ";
}
};
class DerivedClassB : virtual public BaseClass
{
public:
void print() const
{
cout << "3";
}
};
class Multiple : public DerivedClassA, DerivedClassB
{
public:
void print() const
{
DerivedClassB::print();
}
};
int main()
{
Multiple both;
DerivedClassA objectA;
DerivedClassB objectB;
BaseClass *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &objectA;
array[ 2 ] = &objectB;
for ( int K = 0; K < 3; K++ )
array[ K ] -> print();
return 0;
}

A. 5 3
B. 3 5 3
C. 3 3 5
D. 5 3 3
E. None of these
Answer» C. 3 3 5


Discussion

No Comment Found

Related MCQs