Test Series - cpp

Test Number 4/102

Q: Which operator is overloaded for a cout object?
A. >>
B. <<
C. <
D. >
Solution: cout in C++ uses << operator to print anything so << operator is overloaded for a cout object.
Q: Which of the following cannot be used with the virtual keyword?
A. Class
B. Member functions
C. Constructors
D. Destructors
Solution: Virtual keyword cannot be used with constructors as constructors are defined to initialized an object of particular class hence no other class needs constructor of other class.
Q: Which concept is used to implement late binding?
A. Virtual functions
B. Operator functions
C. Constant functions
D. Static functions
Solution: Virtual functions are used to implement the concept of late binding i.e. binding actual functions to their calls.
Q: Which of the following is correct?
A. C++ allows static type checking
B. C++ allows dynamic type checking.
C. C++ allows static member function to be of type const.
D. C++ allows both static and dynamic type checking
Solution: C++ allows both static and dynamic type checking i.e. types are checked by the compiler.
Q: Which of the following supports the concept that reusability is a desirable feature of a language?
A. It reduces the testing time
B. It reduces maintenance cost
C. It decreases the compilation time
D. It reduced both testing and maintenance time
Solution: As we will be using the existing code therefore we don’t need to check the code again and again so testing and maintenance time decreases but the compiler time may increase or remains same because though we are reusing the code but every part needs to be compiled and extra include statement needs to be executed therefore compilation time may remain same or increases.
Q: Which of the following is a static polymorphism mechanism?
A. Function overloading
B. Operator overloading
C. Templates
D. All of the mentioned
Solution: All the options mentioned above uses static polymorphism mechanism. As the conflicts in all these types of functions are resolved during compile-time.
Q: Which of the following is true?
I) All operators in C++ can be overloaded.
II) The basic meaning of an operator can be changed.
A. I only
B. II only
C. Both I and II
D. Neither I nor II
Solution: Both statements are false because all the operators of C++ cannot be overloaded and the basic meaning of an operator cannot be changed, we can only give new meaning to an operator.
Q: Which of the following is not a type of inheritance?
A. Multiple
B. Multilevel
C. Distributive
D. Hierarchical
Solution: Distributive is not a type of inheritance whereas others are a type of inheritance having their own meaning.
Q: What happens if a class does not have a name?
A. It will not have a constructor
B. It will not have a destructor
C. It is not allowed
D. It will neither have a constructor or destructor
Solution: A class without a name will not have a destructor. The object is made so constructor is required but the destructor is not. Check the code below:
#include 
using namespace std;
class
{
    public:
	void func()
        {
		cout<<"Hello world";
	}
}a;
int main(int argc, char const *argv[])
{
	a.func();
	return 0;
}
Q: Which of the following is correct?
A. A class is an instance of its objects
B. An object is an instance of its class
C. A class is an instance of the data type that the class have
D. An object is an instance of the data type of the class
Solution: An object is an instance of a class i.e. an object represents a class i.e. what class has(data members) and what it can do(member functions).

You Have Score    /10