C++ Programming - Constructors and Destructors
Exercise : Constructors and Destructors - Programs
- Constructors and Destructors - General Questions
- 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;
}
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;
}
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;
}
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;
}
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;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers