Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Base
{
    public:
    virtual void print() const = 0;
};
class DerivedOne : public Base
{
    public:     
    void print() const
    {
        cout << "DerivedOne\n";
    }
};
class DerivedTwo : public Base
{
    public:
    void print() const
    {
        cout << "DerivedTwo\n";
    }     
}; 
class Multiple : public DerivedOne, public DerivedTwo
{
    public:
    void print() const
    {
        DerivedTwo :: print();
    } 
}; 
int main()
{
    int i;
    Multiple both; 
    DerivedOne one; 
    DerivedTwo two; 
    Base *array[ 3 ]; 
    array[ 0 ] = &both; 
    array[ 1 ] = &one;
    array[ 2 ] = &two;
    array[ i ] -> print();
    return 0;
}

A. DerivedOne

B. DerivedTwo

C. Error

D. DerivedThree

Answer: Option C


Join The Discussion

Related Questions on Inheritance in C plus plus