![]() |
VOOZH | about |
Question 1
Given the following class definition, which of the following statements is true regarding object construction and destruction?
Constructor and Destructor will be called once.
Constructor will be called twice, Destructor once.
Constructor and Destructor will be called twice.
Constructor will be called once, Destructor twice.
Question 2
How to implement a class in C++ to prevent it from being inherited?
By making all constructors private.
By declaring the class as sealed.
By using the final keyword.
By making all methods private.
Question 3
What will be the output of the following code?
Only Base Destructor is called
Base Constructor, Derived Constructor, and Base Destructor are called.
Base Constructor, Derived Constructor, Derived Destructor, and Base Destructor are called.
Base Constructor, Derived Constructor, and Derived Destructor are called.
Question 4
What would be the outcome if the following setter method were used to modify a private member without validation?
It prevents setting invalid values by default.
It allows for any value to be set, including invalid states.
It automatically rounds off the value to the nearest integer.
It throws a runtime exception if the value is negative.
Question 5
Consider the following code. What will happen if the getter method is not declared as const?
The method can modify the class's internal state.
The method will automatically become a const method.
The method will return a reference to the internal state.
The method cannot be called on const instances of MyClass.
Question 6
What will be the output of the following code, considering the presence of slicing?
Base
Derived
Base followed by Derived
Compilation error
Question 7
What will be the output of the following code?
Base Constructor, Derived Constructor, Base Destructor
Derived Constructor, Base Destructor, Derived Destructor
Base Constructor, Derived Constructor, Derived Destructor, Base Destructor
Compilation error
Question 8
What will be the output of the following code?
Base Display
Derived Display
Base Display followed by Derived Display
Compilation error
Question 9
Which among the following is the correct way to implement an abstract class in C++?
By declaring a class as abstract
By marking all member functions as virtual
By inheriting from another abstract class
By having at least one pure virtual function
Question 10
What will be the output of the following code?
7 and 2.1
Compilation error
7 and 3.5
Undefined behavior
There are 37 questions to complete.