Question 1 of 25
Hints left: 3
Q1
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; }; int main(int argc, char const *argv[]) { A a1 = {10}; A a2 = a1; cout<<a1.a<<a2.a; return 0; }
Q2
What is the process of creating a new class using an existing class as a base in C++?
Q3
What is the process of defining a new class by extending an existing class in C++?
Q4
What happens if a user forgets to define a constructor inside a class?
Q5
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A{ int a; A(){ a = 5; } public: void assign(int i){ a = i; } int return_value(){ return a; } }; int main(int argc, char const *argv[]) { A obj; obj.assign(10); cout<<obj.return_value(); }
Q6
Which keyword is used to signify inheritance in C++?
Q7
What is the name given to the feature of C++ where a class inherits features from more than one base class?
Q8
What is the diamond problem in C++?
Q9
What is the default access specifier for members of a class in C++ when using inheritance?
Q10
What is the access specifier that restricts access to members of a class to only its derived classes in C++?
Q11
In C++, which access specifier allows members of a base class to be accessible in the derived class but not to the outside world?
Q12
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ A(){ cout<<"A's Constructor called\n"; } friend class B; }; class B { public: A a; B(){ cout<"B's constructor called\ns"; } }; int main(int argc, char const *argv[]) { B b; return 0; }
Q13
In C++, if a derived class does not define a constructor, which constructor of the base class is called during the object creation of the derived class?
Q14
What is the process of defining a new class based on an existing class in C++ called?
Q15
In C++, which type of inheritance allows a class to inherit from multiple classes directly or indirectly?
Q16
In C++, which type of inheritance is not supported directly but can be achieved using a combination of other types of inheritance?
Q17
What is the name for the process by which a class inherits features from another class in C++?
Q18
What happens if a derived class redefines a method that is already defined in its base class in C++?
Q19
In C++, which type of inheritance allows a class to inherit properties and behavior from multiple base classes?
Q20
How many Destructors are allowed in a Class?
Q21
What will be the output of the following C++ code? #include <iostream> using namespace std; class A{ public: int a; A(){ cout<<"Constructor called\n"; } } a; int main(int argc, char const *argv[]) { cout<<"Main function\n"; return 0; }
Q22
In C++, which access specifier allows the members of a base class to be accessible in the derived class as well as from outside the class?
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: public A{ 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
What is the role of a constructor in classes?
Q25
What is the term used to describe a derived class having more than one base class in C++?