Cpp : Constructors And Destructors 15

6.
Which of the following is true about constructors.
i) They cannot be virtual
ii) They cannot be private.
iii) They are automatically called by new operator.

A. All i,ii,iii
B. i & iii
C. ii & iii
D. i & ii

7.
Destructors __________ for automatic objects if the program terminates with a call to function exit or function abort

A. Are called
B. Are not called
C. Are inherited
D. Are created

8.
Which contructor function is designed to copy object of same class type?

A. Copy constructor
B. Create constructor
C. Object constructor
D. Dynamic constructor


9.
What will be the output of the following program?

#include <iostream>
using namespace std;

class catalyst
{
int id;
static int count;
public:
catalyst() {
count++;
id = count;
cout << “constructor for id ” << id << endl;
}
~catalyst() {
cout << “destructor for id ” << id << endl;
}
};

int catalyst::count = 0;

int main() {
catalyst a[3];
return 0;
}

A.
constructor for id 1
constructor for id 2
constructor for id 3
destructor for id 3
destructor for id 2
destructor for id 1
B.
constructor for id 1
constructor for id 2
constructor for id 3
destructor for id 1
destructor for id 2
destructor for id 3
C. Compiler Dependent
D.
constructor for id 1
destructor for id 1

10.
What will be the output of the following program?

#include <iostream>
using namespace std;
class catalyst {
catalyst() { cout << “Constructor called”; }
};

int main()
{
catalyst t1;
return 0;
}

A. Compiler Error
B. Runtime Error
C. Constructor called
D. destructor for id 1