C++ OOPs Concepts | Set 2
11. 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
Answer: C
Explanation: 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.
12. Which of the following is not a type of Constructor?
a) Friend constructor
b) Copy constructor
c) Default constructor
d) Parameterized constructor
Answer: A
Explanation: Friend function is not a constructor whereas others are a type of constructor used for object initialization.
13. 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
Answer: B
Explanation: 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.
14. Out of the following, which is not a member of the class?
a) Static function
b) Friend function
c) Constant function
d) Virtual function
Answer: B
Explanation: 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.
15. What is the other name used for functions inside a class?
a) Member variables
b) Member functions
c) Class functions
d) Class variables
Answer: B
Explanation: Functions of a class are also known as member functions of a class.
16. Which of the following cannot be a friend?
a) Function
b) Class
c) Object
d) Operator function
Answer: C
Explanation: 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.
17. 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
Answer: B
Explanation: 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.
18. 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
Answer: B
Explanation: The concept of using objects of one class into another class is known as Composition.
19. How many types of polymorphism are there in C++?
a) 1
b) 2
c) 3
d) 4
Answer: B
Explanation: There are two types of polymorphism in C++ namely run-time and compile-time polymorphisms.
20. How run-time polymorphisms are implemented in C++?
a) Using Inheritance
b) Using Virtual functions
c) Using Templates
d) Using Inheritance and Virtual functions
Answer: D
Explanation: Run-time polymorphism is implemented using Inheritance and virtual in which object decides which function to call.