Exercise: Constructors And Destructors

Questions for: Constructors And Destructors

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
Answer: B
No answer description is available. Let's discuss.
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.
Answer: D
No answer description is available. Let's discuss.
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.
Answer: B
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class ExamAdept
{
    int x; 
    public:
    ExamAdept(short ss)
    {
        cout<< "Short" << endl;
    }
    ExamAdept(int xx)
    {
        cout<< "Int" << endl;
    }
    ExamAdept(float ff)
    {
        cout<< "Float" << endl;
    }
    ~ExamAdept() 
    {
        cout<< "Final";
    }
};
int main()
{
    ExamAdept *ptr = new ExamAdept('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 .
Answer: B
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class ExamAdept
{
    int x; 
    public:
    ExamAdept(short ss)
    {
        cout<< "Short" << endl;
    }
    ExamAdept(int xx)
    {
        cout<< "Int" << endl;
    }
    ExamAdept(char ch)
    {
        cout<< "Char" << endl;
    }
    ~ExamAdept() 
    {
        cout<< "Final";
    }
};
int main()
{
    ExamAdept *ptr = new ExamAdept('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 .
Answer: C
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz