ExamVeda
Login
Home
Inheritance in C plus plus
?

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;
}

Answer & Solution
Correct Answer: Option C
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.