Test Series - cpp

Test Number 3/102

Q: Which of the following class allows to declare only one object of it?
A. Abstract class
B. Virtual class
C. Singleton class
D. Friend class
Solution: Singleton class allows the programmer to declare only one object of it, If one tries to declare more than one object the program results into error.
Q: Which of the following is not a type of Constructor?
A. Friend constructor
B. Copy constructor
C. Default constructor
D. Parameterized constructor
Solution: Friend function is not a constructor whereas others are a type of constructor used for object initialization.
Q: Which of the following is correct?
A. Base class pointer object cannot point to a derived class object
B. Derived class pointer object cannot point to a base class object
C. A derived class cannot have pointer objects
D. A base class cannot have pointer objects
Solution: C++ does not allow a derived class pointer to point a base class pointer whereas Base class can point to a derived class object. Both base class and derived class can have pointer objects.
Q: Out of the following, which is not a member of the class?
A. Static function
B. Friend function
C. Constant function
D. Virtual function
Solution: Friend function is not a member of the class. They are given the same access rights as the class member function have but they are not actual members of the class.
Q: What is the other name used for functions inside a class?
A. Member variables
B. Member functions
C. Class functions
D. Class variables
Solution: Functions of a class are also known as member functions of a class.
Q: Which of the following cannot be a friend?
A. Function
B. Class
C. Object
D. Operator function
Solution: Objects of any class cannot be made a friend of any other or same class whereas functions, classes and operator functions can be made a friend.
Q: Why references are different from pointers?
A. A reference cannot be made null
B. A reference cannot be changed once initialized
C. No extra operator is needed for dereferencing of a reference
D. All of the mentioned
Solution: References cannot be made null whereas a pointer can be. References cannot be changed whereas pointers can be modified.
Pointers need * operator to dereference the value present inside it whereas reference does not need an operator for dereferencing.
Q: Which of the following provides a programmer with the facility of using object of a class inside other classes?
A. Inheritance
B. Composition
C. Abstraction
D. Encapsulation
Solution: The concept of using objects of one class into another class is known as Composition.
Q: How many types of polymorphism are there in C++?
A. 1
B. 2
C. 3
D. 4
Solution: There are two types of polymorphism in C++ namely run-time and compile-time polymorphisms.
Q: How run-time polymorphisms are implemented in C++?
A. Using Inheritance
B. Using Virtual functions
C. Using Templates
D. Using Inheritance and Virtual functions
Solution: Run-time polymorphism is implemented using Inheritance and virtual in which object decides which function to call.

You Have Score    /10