Exercise: Constructors And Destructors
Questions for: Constructors And Destructors
What is the technical word for the function ~ExamAdept() defined in the following program?
#include<iostream.h>
class ExamAdept
{
int x, y;
public:
ExamAdept(int xx = 10, int yy = 20 )
{
x = xx;
y = yy;
}
void Display()
{
cout<< x << " " << y << endl;
}
~ExamAdept()
{ }
};
int main()
{
ExamAdept objBix;
objBix.Display();
return 0;
}
A:
Constructor
B:
Destructor
C:
Default Destructor
D:
Function Template
Answer: B
No answer description is available. Let's discuss.
What will be the output of the following program?
#include<iostream.h>
class ExamAdept
{
int x, y;
public:
ExamAdept(int xx)
{
x = ++xx;
}
~ExamAdept()
{
cout<< x - 1 << " ";
}
void Display()
{
cout<< --x + 1 << " ";
}
};
int main()
{
ExamAdept objBix(5);
objBix.Display();
int *p = (int*) &objBix;
*p = 40;
objBix.Display();
return 0;
}
A:
6 6 4
B:
6 6 5
C:
5 40 38
D:
6 40 38
Answer: D
No answer description is available. Let's discuss.
Discuss About this Question.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<< "Base OK. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<< "Derived OK. ";
}
~BixDerived()
{
cout<< "Derived DEL. ";
}
};
int main()
{
BixBase objB;
BixDerived objD;
objD.~BixDerived();
return 0;
}
A:
Base OK. Derived OK. Derived DEL.
B:
Base OK. Base OK. Derived OK. Derived DEL.
C:
Base OK. Derived OK. Derived DEL. Derived DEL.
D:
Base OK. Base OK. Derived OK. Derived DEL. Derived DEL.
Answer: D
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following constructor is used in the program given below?
#include<iostream.h>
class ExamAdept
{
int x, y;
public:
ExamAdept(int xx = 10, int yy = 20 )
{
x = xx;
y = yy;
}
void Display()
{
cout<< x << " " << y << endl;
}
~ExamAdept()
{ }
};
int main()
{
ExamAdept objBix;
objBix.Display();
return 0;
}
A:
Copy constructor
B:
Simple constructor
C:
Non-parameterized constructor
D:
Default constructor
Answer: D
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 *p;
public:
ExamAdept(int xx, char ch)
{
p = new int();
*p = xx + int(ch);
cout<< *p;
}
~ExamAdept()
{
delete p;
}
};
int main()
{
ExamAdept objBix(10, 'B');
return 0;
}
A:
The program will print the output 76.
B:
The program will print the output 108.
C:
The program will print the output garbage value.
D:
The program will report compile time error.
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.