C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 19)
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;
}
11 22 0 0
11 0 0 22
11 0 22 0
11 22 11 22
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Neha said:   7 years ago
Thanks for explaining it @Rt45.

Ravi said:   1 decade ago
Not clear please explain above program with simple example. Thanks in advance.

Rt45 said:   1 decade ago
Here xx=11 and yy=22.

The constructor for BixBase is called with argument xx=11, n default argument yy=0;

The constructor for objbase is called with argument xx=22, n default argument yy=0;

Shanu said:   1 decade ago
Please explain it.

Post your comments here:

Your comments will be displayed after verification.