sInfoEra
Home
MCQs
C C — Quiz
C Programming -Constructors and Destructors
38 questions · Test your knowledge
Home
/
MCQs
/
C Programming -Constructors and Destructors
1
A constructor that accepts __________ parameters is called the default constructor.
A
one
B
two
C
no
D
three
2
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
A
Compile-time error.
B
Preprocessing error.
C
Runtime error.
D
Runtime exception.
3
Destructor has the same name as the constructor and it is preceded by ______ .
A
!
B
?
C
~
D
$
4
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
5
Which constructor function is designed to copy objects of the same class type?
A
Create constructor
B
Object constructor
C
Dynamic constructor
D
Copy constructor
6
Which of the following statement is correct?
A
Constructor has the same name as that of the class.
B
Destructor has the same name as that of the class with a tilde symbol at the beginning.
C
Both A and B.
D
Destructor has the same name as the first member function of the class.
7
Which of the following statement is incorrect?
A
Constructor is a member function of the class.
B
The compiler always provides a zero argument constructor.
C
It is necessary that a constructor in a class should always be public.
D
Both B and C.
8
When are the Global objects destroyed?
A
When the control comes out of the block in which they are being used.
B
When the program terminates.
C
When the control comes out of the function in which they are being used.
D
As soon as local objects die.
9
Copy constructor must receive its arguments by __________ .
A
either pass-by-value or pass-by-reference
B
only pass-by-value
C
only pass-by-reference
D
only pass by address
10
A function with the same name as the class, but preceded with a tilde character (~) is called __________ of that class.
A
constructor
B
destructor
C
function
D
object
11
A union that has no constructor can be initialized with another union of __________ type.
A
different
B
same
C
virtual
D
class
12
Which of the following gets called when an object goes out of scope?
A
constructor
B
destructor
C
main
D
virtual function
13
Which of the following statement is correct?
A
Destructor destroys only integer data members of the object.
B
Destructor destroys only float data members of the object.
C
Destructor destroys only pointer data members of the object.
D
Destructor destroys the complete object.
14
________ used to make a copy of one class object from another class object of the same class type.
A
constructor
B
copy constructor
C
destructor
D
default constructor
15
Constructors __________ to allow different approaches of object construction.
A
cannot overloaded
B
can be overloaded
C
can be called
D
can be nested
16
Which of the following statement is correct?
A
A destructor has the same name as the class in which it is present.
B
A destructor has a different name than the class in which it is present.
C
A destructor always returns an integer.
D
A destructor can be overloaded.
17
Which of the following cannot be declared as virtual?
A
Constructor
B
Destructor
C
Data Members
D
Both A and C
18
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
19
Which of the following are NOT provided by the compiler by default?
A
Zero-argument Constructor
B
Destructor
C
Copy Constructor
D
Copy Destructor
20
It is a __________ error to pass arguments to a destructor.
A
logical
B
virtual
C
syntax
D
linker
21
If the programmer does not explicitly provide a destructor, then which of the following creates an empty destructor?
A
Preprocessor
B
Compiler
C
Linker
D
main() function
22
A __________ is a constructor that either has no parameters, or if it has parameters, all the parameters have default values
A
default constructor
B
copy constructor
C
Both A and B
D
None of these
23
How many default constructors per class are possible?
A
Only one
B
Two
C
Three
D
Unlimited
24
Which of the following statement is correct about destructors?
A
A destructor has void return type.
B
A destructor has integer return type.
C
A destructor has no return type.
D
A destructors return type is always same as that of main().
25
Which of the following statement is correct?
A
A constructor has the same name as the class in which it is present.
B
A constructor has a different name than the class in which it is present.
C
A constructor always returns an integer.
D
A constructor cannot be overloaded.
26
Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?
A
Preprocessor
B
Linker
C
Loader
D
Compiler
27
A destructor takes __________ arguments.
A
one
B
two
C
three
D
no
28
Destructor calls are made in which order of the corresponding constructor calls?
A
Reverse order
B
Forward order
C
Depends on how the object is constructed
D
Depends on how many objects are constructed
29
Which of the following never requires any arguments?
A
Member function
B
Friend function
C
Default constructor
D
const function
30
A class's __________ is called when an object is destroyed.
A
constructor
B
destructor
C
assignment function
D
copy constructor
31
Destructors __________ for automatic objects if the program terminates with a call to function exit or function abort.
A
are called
B
are inherited
C
are not called
D
are created
32
Which of the following statement is correct?
A
A constructor of a derived class can access any public and protected member of the base class.
B
Constructor cannot be inherited but the derived class can call them.
C
A constructor of a derived class cannot access any public and protected member of the base class.
D
Both A and B.
33
Which of the following statements are correct?
A
Constructor is always called explicitly.
B
Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly.
C
Destructor is always called explicitly.
D
Constructor and destructor functions are not called at all as they are always inline.
34
How many times a constructor is called in the life-time of an object?
A
Only once
B
Twice
C
Thrice
D
Depends on the way of creation of object
35
Which of the following gets called when an object is being created?
A
constructor
B
virtual function
C
destructor
D
main
36
To ensure that every object in the array receives a destructor call, always delete memory allocated as an array with operator __________ .
A
destructor
B
delete
C
delete[]
D
kill[]
37
Which of the following statement is correct about constructors?
A
A constructor has a return type.
B
A constructor cannot contain a function call.
C
A constructor has no return type.
D
A constructor has a void return type.
38
Which of the following statement is correct whenever an object goes out of scope?
A
The default constructor of the object is called.
B
The parameterized destructor is called.
C
The default destructor of the object is called.
D
None of the above.
Submit Quiz
Back to All Quizzes