Constructors interview questions
24 questions. Tap “Show answer” to check yourself.
-
A destructor name must be
- same as class name prefixed by tilde (~) character
- same as class name
- same as any other member function name
- none of the given
Show answer
A. same as class name prefixed by tilde (~) character
-
Which of the following prototype can be a copy constructor of class myclass?
- myclass (myclass & ×)
- myclass copy (myclass a)
- int copy (myclass mc)
- myclass (int myclass)
Show answer
A. myclass (myclass & ×)
-
A copy constructor is invoked when
- an object is passed by reference to constructor
- a member function returns an object
- an object is passed as a parameter to any of the member function
- all of the above
Show answer
D. all of the above
-
Which of the following is not true?
- Destructors cannot be overloaded
- Constructor can have parameters
- Constructor is executed automatically
- Constructor cannot be Overloaded
Show answer
D. Constructor cannot be Overloaded
-
Which of the following is false?
- Constructor and member function have same name
- Class and destructor have same name
- Class and constructor have same name
- Constructor and destructor have same name
Show answer
A. Constructor and member function have same name
-
Which of the following is automatically executed when the control reaches the end of class scope?
- Inline function
- Member function
- Destructor
- Constructor
Show answer
C. Destructor
-
Which of the following is a function that removes the allocated memory of an object?
- Copy constructor
- Member function
- Destructor
- Constructor
Show answer
C. Destructor
-
Which of the following is true?
- The constructor function can be overloaded
- The constructor is executed automatically
- A constructor can have parameter list
- All the given are true
Show answer
D. All the given are true
-
Which one of the following initializes a class object and allocates memory space?
- Member function
- Constructor
- Destructor
- None of the given
Show answer
B. Constructor
-
When a class object goes out of scope, the function that gets executed is ____
- Constructor
- Destructor
- Friend
- Inline
Show answer
B. Destructor
-
Which is executed automatically when the control reaches the end of the class scope?
- Constructor
- Destructor
- Overloading
- Copy constructor
Show answer
B. Destructor
-
The special character related to destructor is ___
- +
- !
- ?
- ~
Show answer
D. ~
- Advertisement
-
The constructor without any parameter is called as ___
- Initial constructor
- Parameterized constructor
- Default constructor
- Instance parameter
Show answer
B. Parameterized constructor
-
The constructor defined by the computers in the absence of user defined constructor is ____
- Copy
- Abstract
- Default
- Destructor
Show answer
C. Default
-
The constructors defined by the computers in the absence of user defined constructor is called as ____
- Non-parameterized
- Default
- Compiler generated
- All of these
Show answer
C. Compiler generated
-
How many destructors a class can have?
- 1
- 2
- 3
- 4
Show answer
A. 1
-
Constructor should be declared under the scope ___
- Public
- Private
- Protected
- Pointer
Show answer
A. Public
-
Which of the following cannot have arguments?
- Operator overloading
- Function overloading
- Constructor
- Destructor
Show answer
D. Destructor
-
Which of the following do not return any value ____
- Constructor and destructor
- Friend functions
- Inline functions
- Member functions
Show answer
A. Constructor and destructor
-
When an instance of a class comes into scope, the function that executed is ____
- Destructor
- Constructor
- Inline
- Friend
Show answer
B. Constructor
-
The destructor is prefixed by the character ___
- ~
- %
- #
- &
Show answer
A. ~
-
Which one of the following is automatically executed when an object is created?
- Constructor
- Destructor
- Inline function
- Member function
Show answer
A. Constructor
-
The name of constructor must be ___
- Same as object name
- Same as one of the member function
- Same as class name
- None of the given
Show answer
C. Same as class name
-
When an object is passed by reference to constructor, the constructor that is executed is _____
- Inline
- Default
- Static
- Copy
Show answer
D. Copy