Question 1 of 25
Hints left: 3
Q1
What happens if a destructor is made private in a C++ class?
Q2
What is the purpose of using constructor initialization lists in C++?
Q3
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); }
Q4
What is the purpose of the destructor in C++?
Q5
How constructors are different from other member functions of the class?
Q6
Which of the following statements is true about constructors in C++?
Q7
Which of the following is correct?
Q8
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++?
Q9
In C++, which type of constructor is called when an object is created without any arguments?
Q10
What is the destructor called automatically when an object is destroyed in C++?
Q11
Which statement about constructor inheritance in C++ is correct?
Q12
What happens if a constructor throws an exception in C++?
Q13
What is the purpose of using default arguments in C++ constructors?
Q14
In C++, what is the order of constructor and destructor calls for a class hierarchy?
Q15
Which keyword is used to prevent an object from being copied in C++?
Q16
Which keyword is used to create a copy constructor in C++?
Q17
How destructor overloading is done?
Q18
What is the primary purpose of the explicit keyword in a C++ constructor?
Q19
What happens if the destructor is explicitly defined in a C++ class, but the constructor is not defined?
Q20
Which statement about destructors in C++ is true?
Q21
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; }
Q22
In C++, which function cannot be inherited but can be overridden in a derived class?
Q23
What is the purpose of using the delete keyword in C++ destructors?
Q24
Which of the following statements about constructor initialization lists in C++ is correct?
Q25
Which operator is used to access members of an object in C++?