C++ Programming - Constructors and Destructors

Exercise :: Constructors and Destructors - Programs

16. 

What will be the out of the following program?

#include<iostream.h> 
class BixBase
{
    protected:
    int x, y; 
    public:
    BixBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
    void Show()
    {
        cout<< x * this->y << endl;
    }
};
class BixDerived
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : objBase(xx, yy)
    {
        objBase.Show();
    } 
    ~BixDerived()
    { }
};
int main()
{
    BixDerived objDev(10, 20); 
    return 0;
}

A. 0
B. 100
C. 200
D. 400
E. The program will report compile time error.

Answer: Option C

Explanation:

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

17. 

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

#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
        IndiaBix()
        {
           x = 0;
        }
        IndiaBix(int xx)
        {
            x = xx; 
        }
        IndiaBix(IndiaBix &objB)
        {
            x = objB.x; 
        }
        void Display()
        {
            cout<< x << " ";
        }
};
int main()
{
    IndiaBix objA(25);
    IndiaBix objB(objA);
    IndiaBix objC = objA;
    objA.Display();
    objB.Display();
    objC.Display();
    return 0; 
}

A. The program will print the output 25 25 25 .
B. The program will print the output 25 Garbage 25 .
C. The program will print the output Garbage 25 25 .
D. The program will report compile time error.

Answer: Option A

Explanation:

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

18. 

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

#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
        IndiaBix()
        {
            x = 0;
            y = 0; 
        }
        IndiaBix(int xx, int yy)
        {
            x = xx;
            y = yy; 
        }
        IndiaBix(IndiaBix *objB)
        {
            x = objB->x;
            y = objB->y; 
        }
        void Display()
        {
            cout<< x << " " << y;
        }
};
int main()
{
    IndiaBix objBix( new IndiaBix(20, 40) );
    objBix.Display();
    return 0; 
}

A. The program will print the output 0 0 .
B. The program will print the output 20 40 .
C. The program will print the output Garbage Garbage .
D. The program will report compile time error.

Answer: Option B

Explanation:

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

19. 

What will be the out of the following program?

#include<iostream.h> 
class BixBase
{
    public:
    int x, y; 
    public:
    BixBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class BixDerived : public BixBase
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : BixBase(xx), objBase(yy)
    {
        cout << this->x   << " " 
             << this->y   << " "  
             << objBase.x << " "
             << objBase.y << " ";
    } 
    ~BixDerived()
    { }
};
int main()
{
    BixDerived objDev(11, 22); 
    return 0;
}

A. 11 22 0 0
B. 11 0 0 22
C. 11 0 22 0
D. 11 22 11 22
E. The program will report compile time error.

Answer: Option C

Explanation:

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

20. 

What will be the out of the following program?

#include<iostream.h> 
class BixBase
{
    public:
    int x, y; 
    public:
    BixBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class BixDerived : public BixBase
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : BixBase(xx), objBase(yy)
    {
        cout << x          << " " 
             << this->x    << " "  
             << BixBase::x << " "     
             << this->objBase.x ;
    } 
    ~BixDerived()
    { }
};
int main()
{
    BixDerived objDev(11, 22); 
    return 0;
}

A. 11 22 0 0
B. 11 11 0 22
C. 11 11 11 0
D. 11 11 11 22
E. The program will report compile time error.

Answer: Option D

Explanation:

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

« Prev   1 2 3 4