Constructor & Destructor

25. What will be the output of the following program?
Note:Includes all required header files

using namespace std;
class find
{
int id;
static int count;
public:
find() {
count++;
id = count;
cout << "constructor for id " << id << endl;
}
~find() {
cout << "destructor for id " << id << endl;
}
};
int find::count = 0;
int main() {
find 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
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

View Answer


26. What will be the output of the following program?
Note:Includes all required header files

using namespace std;
class find {
find() { cout << "Constructor called"; }
};
int main()
{
find t1;
return 0;
}

A. Compiler Error
B. Runtime Error
C. Constructor called
D. None of the above

View Answer


27. If the copy constructor receives its arguments by value, the copy constructor would

A. Call one-argument constructor of the class
B. Work without any problem
C. Call itself recursively
D. Call zero-argument constructor

View Answer


28.which of this can not be declared as virtual

A. Constructor
B. Destructor
C Both A & B
D. None of the above

View Answer


29.For automatic objects, constructors and destructors are called each time the objects

A. Enter and leave scope
B. Inherit parent class
C. Are constructed
D. Are destroyed

View Answer


30.An ………………….. with a constructor or destructor cannot be used as a member or a union

A. Class
B. Object
C. Function.
D. Varible

View Answer


31.Choose the correct statements.

A. A destructor is not inherited
B. A constructor cannot be called explicitly
C. A constructor is not inherited
D. All of the above

View Answer


32. Which of the following remarks about the differences between constructors and destructors are correct ?

A. Constructors can take arguments but destructors cannot.
B. Constructors can be overloaded but destructors cannot be overloaded.
C. Destructors can take arguments but constructors cannot.
D. Both A and B

View Answer






Also check :


Discussion


* You must be logged in to add comment.