Question 1 of 25
Hints left: 3
Q1
In C++, what is the order of constructor and destructor calls for a class hierarchy?
Q2
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ mutable int a; public: A(){ cout<<"Default constructor called\n"; } A(const A& a){ cout<<"Copy Constructor called\n"; } }; int main(int argc, char const *argv[]) { A obj; A a1 = obj; A a2(obj); }
Q3
Which of the following statements about constructor initialization lists in C++ is correct?
Q4
What is the primary purpose of the explicit keyword in a C++ constructor?
Q5
What is the purpose of the destructor in C++?
Q6
Which statement about constructor inheritance in C++ is correct?
Q7
What happens if a constructor throws an exception in C++?
Q8
In C++, which type of constructor is called when an object is created without any arguments?
Q9
What is the destructor called automatically when an object is destroyed in C++?
Q10
What is the access specifier that allows constructors to be called only from member functions of the same class and its derived classes in C++?
Q11
Which statement about destructors in C++ is true?
Q12
What is the purpose of using the delete keyword in C++ destructors?
Q13
What happens if a destructor is made private in a C++ class?
Q14
What happens if the destructor is explicitly defined in a C++ class, but the constructor is not defined?
Q15
Which operator is used to access members of an object in C++?
Q16
How constructors are different from other member functions of the class?
Q17
What is the purpose of using default arguments in C++ constructors?
Q18
Which of the following statements is true about constructors in C++?
Q19
Which keyword is used to prevent an object from being copied in C++?
Q20
How destructor overloading is done?
Q21
In C++, which function cannot be inherited but can be overridden in a derived class?
Q22
What is the purpose of using constructor initialization lists in C++?
Q23
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ mutable int a; public: A(){ cout<<"A's Constructor called\n"; } ~A(){ cout<<"A's Destructor called\n"; } }; class B{ A a; public: B(){ cout<<"B's Constructor called\n"; } ~B(){ cout<<"B's Destructor called\n"; } }; int main(int argc, char const *argv[]) { B b1; }
Q24
Which of the following is correct?
Q25
Which keyword is used to create a copy constructor in C++?