Functions

Q1: What will be the output of the following program?
#include<iostream.h> 
class Base
{
    int x, y; 
    public:
    Base() 
    {
        x = y = 0; 
    } 
    Base(int xx)
    {
        x = xx;
    }
    Base(int p, int q = 10)
    {
        x = p + q;
        y = q; 
    } 
    void Display(void)
    {
        cout<< x << ' ' << y << endl;
    } 
}objDefault(1, 1);

class Derived: public Base
{
    Base obj; 
    public:
    Derived(int xx, int yy): Base(xx, xx + 1)
    { }
    Derived(Base objB = objDefault)
    { } 
}; 
int main()
{
    Derived objD(5, 3);
    Derived *ptrD = new Derived(objD);
    ptrD->Display();
    delete ptrD;
    return 0; 
}

A 11 10

B 3 2

C 11 6

D The program will not compile successfully.

E 8 3

ANS:C - 11 6

No answer description is available. Let's discuss.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.