Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class BaseClass 
{
    protected:
    int i;
    public:
    BaseClass(int x) 
    {
        i = x;
    }
    ~BaseClass() 
    {
    }
};
class DerivedClass: public BaseClass 
{
    int j;
    public:
    DerivedClass(int x, int y): BaseClass(y)
    {
        j = x;
    }
    ~DerivedClass() 
    {
    }
    void show() 
    {
        cout << i << " " << j << endl;
    }
};
int main()
{
    DerivedClass ob(3, 4);
    ob.show();
    return 0;
}

A. 3 4

B. 4 3

C. 4

D. 3

Answer: Option B


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it