C++ Programming - Constructors and Destructors - Discussion

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

Tejas B said:   4 years ago
I think, it uses composition. Am I right?

Gautam Kothari said:   5 years ago
How show method is accessible in derived class ?

It is not derived from base class though. It should give compile error.

Chetan Sharma said:   8 years ago
First Ctor of Derived calls get called which is having Ctor member initializer list objBase(xx, yy). this will give call to the base class Ctor where x=10,y=20.

After executing Base Class Ctor control return back to the Derived calls Ctor which will execute gives call to the Show ( ) of Base class.

Abhinaya said:   9 years ago
Please explain the concept.

Ravi said:   1 decade ago
Can anyone please explain it? Thanks in advance.

Ivneet Singh said:   1 decade ago
Value of x and y is always 10 and 20.
Here this.x is always as same as x.

this.y is always as same as y.
Hence multiplying gives 200.

Post your comments here:

Your comments will be displayed after verification.