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;
}
Discussion:
6 comments Page 1 of 1.
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.
After executing Base Class Ctor control return back to the Derived calls Ctor which will execute gives call to the Show ( ) of Base class.
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.
Here this.x is always as same as x.
this.y is always as same as y.
Hence multiplying gives 200.
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.
It is not derived from base class though. It should give compile error.
Ravi said:
1 decade ago
Can anyone please explain it? Thanks in advance.
Tejas B said:
4 years ago
I think, it uses composition. Am I right?
Abhinaya said:
9 years ago
Please explain the concept.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers