1.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
virtual void Function()
{
cout << "4";
}
};
class DerivedClassA : public BaseClass
{
public:
void Function()
{
cout << " 5";
}
};
class DerivedClassB : public DerivedClassA
{
public:
void Function()
{
cout << " 6";
}
};
int main()
{
BaseClass *ptr;
BaseClass BaseObject;
DerivedClassA derivedObjectA;
DerivedClassB derivedObjectB;
ptr = &BaseObject;
ptr -> Function();
ptr = &derivedObjectA;
ptr -> Function();
ptr = &derivedObjectB;
ptr -> Function();
return 0;
}

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


Discussion

No Comment Found

Related MCQs