C++ Programming - Constructors and Destructors

Exercise :: Constructors and Destructors - Programs

11. 

Which of the following statement is correct about the program given below?

#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaBix(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaBix(char ch)
    {
        cout<< "Char" << endl;
    }
    ~IndiaBix() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaBix *ptr = new IndiaBix('B');
    return 0; 
}

A. The program will print the output Short .
B. The program will print the output Int .
C. The program will print the output Char .
D. The program will print the output Final .
E. None of the above

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

12. 

Which of the following statement is correct about the program given below?

#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaBix(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaBix(float ff)
    {
        cout<< "Float" << endl;
    }
    ~IndiaBix() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaBix *ptr = new IndiaBix('B');
    return 0; 
}

A. The program will print the output Short .
B. The program will print the output Int .
C. The program will print the output Float .
D. The program will print the output Final .
E. None of the above

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

13. 

What will be the output of the following program?

#include<iostream.h>
class BixBase
{   
    public:
    BixBase()
    {
        cout<< "Base OK. "; 
    }
    ~BixBase()
    {
        cout<< "Base DEL. "; 
    }
};
class BixDerived: public BixBase
{
    public:
    BixDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~BixDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    BixBase *basePtr = new BixDerived();
    delete basePtr;
    return 0;
}

A. Base OK. Derived OK.
B. Base OK. Derived OK. Base DEL.
C. Base OK. Derived OK. Derived DEL.
D. Base OK. Derived OK. Derived DEL. Base DEL.
E. Base OK. Derived OK. Base DEL. Derived DEL.

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

14. 

What will be the output of the following program?

#include<iostream.h>
class BixBase
{   
    public:
    BixBase()
    {
        cout<< "Base OK. "; 
    }
    virtual ~BixBase()
    {
        cout<< "Base DEL. "; 
    }
};
class BixDerived: public BixBase
{
    public:
    BixDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~BixDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    BixBase *basePtr = new BixDerived();
    delete basePtr;
    return 0;
}

A. Base OK. Derived OK.
B. Base OK. Derived OK. Base DEL.
C. Base OK. Derived OK. Derived DEL.
D. Base OK. Derived OK. Derived DEL. Base DEL.
E. Base OK. Derived OK. Base DEL. Derived DEL.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.

15. 

What will be the output of the following program?

#include<iostream.h> 
class BixBase
{
    public:
    int x, y;
    BixBase(int xx = 0, int yy = 5)
    {
        x = ++xx; 
        y = --yy;
    }
    void Display()
    {
        cout<< --y;
    } 
    ~BixBase(){} 
};
class BixDerived : public BixBase
{
    public:
    void Increment()
    {
        y++;
    }
    void Display()
    {
        cout<< --y;
    } 
}; 
int main()
{
    BixDerived objBix;
    objBix.Increment();
    objBix.Display();
    return 0; 
}

A. 3
B. 4
C. 5
D. Garbage-value
E. The program will report compile time error.

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.