adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #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.

None of the mentioned

Answer: (c).Error

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?