-
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;
}
-
- 4 5 6
- 6 5 4
- 5 6 4
- 6 4 5
- None of these
Correct Option: A
We are passing the objects and executing them in a certain order and we are printing the program flow.