ExamVeda
Login
Home
C plus plus miscellaneous
?

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Base
{
    protected:
    int a;
    public:
    Base() 
    { 
        a = 34; 
    }
    Base(int i)
    { 
       a = i; 
    }
    virtual ~Base() 
    { 
        if (a < 0)  throw a; 
    }
    virtual int getA()
    {
       if (a < 0) 
        { 
            throw a;
        }
    }
};
int main()
{
    try
    {
        Base b(-25);
        cout << endl << b.getA();
    }
    catch (int) 
    {
        cout << endl << "Illegal initialization";
    }
}

Answer & Solution
Correct Answer: Option B
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.