Test Series - cpp

Test Number 59/102

Q: What is the order of Constructors call when the object of derived class B is declared, provided class B is derived from class A?
A. Constructor of A followed by B
B. Constructor of B followed by A
C. Constructor of A only
D. Constructor of B only
Solution: Firstly the Constructor of class A is called then class B because the Constructor of the base class is called before derived class.
Q: What is the order of Destructors call when the object of derived class B is declared, provided class B is derived from class A?
A. Destructor of A followed by B
B. Destructor of B followed by A
C. Destructor of A only
D. Destructor of B only
Solution: Order of Destructor call is just reverse of the order of Destructors call. First, the destructor of the derived class is called then Destructor of the base class is called.
Q: Virtual functions in C++ tells the compiler to perform ______________________ on such functions.
A. static binding
B. late binding
C. compile time binding
D. no binding
Solution: Virtual function in C++ adds the power of late binding by deciding the type of object during run-time.
Q: Which concept of OOPs is shown by Virtual Functions?
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Abstraction
Solution: Virtual function allows us to give different definitions of the same function i.e. overloading of functions which is known as Polymorphism.
Q: Pick the correct statement.
A. Virtual function can have different names in the base and derived class
B. Virtual function cannot be applied in Multiple Inheritance classes
C. Virtual function are different in definitions only
D. Virtual function does early binding
Solution: Virtual functions differ in definitions only, prototype are similar. They does the late binding. They are applicable to all types of inheritance.
Q: Which access specifier is used where one wants data members to be accessed by other classes but not from outside objects?
A. private
B. protected
C. public
D. both protected and public
Solution: Protected and public members are accessible from derived classes but public members can be accessed by objects of the class so protected specifier is the answer.
Q: Which of the following describes the protected access specifier?
A. The variable is visible only outside inside the block
B. The variable is visible everywhere
C. The variable is visible to its block and to it’s derived class
D. The variable is not visible to its block
Solution: Protected members are visible to its block and to the derived classes and not visible to outside objects or variables.
Q: To which of the following access specifiers are applicable?
A. Member data
B. Functions
C. Both Member data & Functions
D. Protected members
Solution: The access specifiers can be applicable to the member data and functions because they need to be accessed outside the block.
Q: Members of which access specifiers are not inherited?
A. Public
B. Protected
C. Private
D. None of the mentioned
Solution: All the data members and member functions of a class are private by default.
Q: What is the importance of mutable keyword?
A. It allows the data member to change within a const member function
B. It will not allow the data member to change within a const member function
C. It will copy the values of the variable
D. It allows the data member to change outside a const member function
Solution: Mutable keyword allows assigning values to a data member belonging to a class defined as “Const” or constant.

You Have Score    /10