Exercise: Constructors And Destructors
Questions for: Constructors And Destructors
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;
}
A:
11 22 0 0
B:
11 11 0 22
C:
11 11 11 0
D:
11 11 11 22
Answer: D
No answer description is available. Let's discuss.
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;
}
A:
11 22 0 0
B:
11 0 0 22
C:
11 0 22 0
D:
11 22 11 22
Answer: C
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class ExamAdept
{
int x, y;
public:
ExamAdept()
{
x = 0;
y = 0;
}
ExamAdept(int xx, int yy)
{
x = xx;
y = yy;
}
ExamAdept(ExamAdept *objB)
{
x = objB->x;
y = objB->y;
}
void Display()
{
cout<< x << " " << y;
}
};
int main()
{
ExamAdept objBix( new ExamAdept(20, 40) );
objBix.Display();
return 0;
}
A:
The program will print the output 0 0 .
B:
The program will print the output 20 40 .
C:
The program will print the output Garbage Garbage .
D:
The program will report compile time error.
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class ExamAdept
{
int x;
public:
ExamAdept()
{
x = 0;
}
ExamAdept(int xx)
{
x = xx;
}
ExamAdept(ExamAdept &objB)
{
x = objB.x;
}
void Display()
{
cout<< x << " ";
}
};
int main()
{
ExamAdept objA(25);
ExamAdept objB(objA);
ExamAdept objC = objA;
objA.Display();
objB.Display();
objC.Display();
return 0;
}
A:
The program will print the output 25 25 25 .
B:
The program will print the output 25 Garbage 25 .
C:
The program will print the output Garbage 25 25 .
D:
The program will report compile time error.
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
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;
}
A:
0
B:
100
C:
200
D:
400
Answer: C
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.