Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Can destructors be virtual in C++?(A) Yes(B) No

Answer»
2.

Predict the output of following C++ program#include <iostream>using namespace std;int i;class A{public:~A(){i=10;}};int foo(){i=3;A ob;return i;}int main(){cout << foo() << endl;return 0;}(A) 0(B) 3(C) 10(D) None of the above

Answer»
3.

#include <iostream>using namespace std;class A{int id;static int count;public:A() {count++;id = count;cout << "constructor for id " << id << endl;}~A() {cout << "destructor for id " << id << endl;}};int A::count = 0;int main() {A a[3];return 0;}(A)constructor for id 1constructor for id 2constructor for id 3destructor for id 3destructor for id 2destructor for id 1(B)constructor for id 1constructor for id 2constructor for id 3destructor for id 1destructor for id 2destructor for id 3(C)Compiler Dependent.(D)constructor for id 1destructor for id 1

Answer» None
4.

Like constructors, can there be more than one destructors in a class?(A) Yes(B) No

Answer»
5.

Can destructors be private in C++?(A) Yes(B) No

Answer»