inheritence - C++ Multiple Choice Questions(MCQs)& Answers

Questions
1 What does inheriatance allows you to do?
A create a class
B create a hierarchy of classes
C access methods
D None of the mentioned

Answer: Option [B]
2 What is the syntax of inheritance of class?
A class name
B class name : access specifer
C class name : access specifer class name
D class name : access specifer class name

Answer: Option [C]
3 How many types of inheritance are there in c++?
A 2
B 3
C 4
D 5

Answer: Option [D]
4 What is meant by containership?
A class contains objects of other class types as its members
B class contains objects of other class types as its objects
C both a & b
D none of the mentioned

Answer: Option [A]
5 How many types of constructor are there in C++?
A 1
B 2
C 3
D 4

Answer: Option [C]
6 The ……………. inherits some or all of the properties of the ……….. class.
A base, derived
B derived, base
C derived, initial
D base, final

Answer: Option [A]
7 In case of inheritance where both base and derived class are having constructors, when an object of derived class is created then___________ .
A constructor of derived class will be invoked first
B constructor of base class will be invoked first
C constructor of derived class will be executed first followed by base class
D constructor of base class will be executed first followed by derived class

Answer: Option [D]
8 If the derived class is struct, then default visibility mode is _______ .
A public
B protected
C private
D struct can’t inherit class

Answer: Option [A]
9 If base class has constructor with arguments, then it is ________________ for the derived class to have constructor and pass the arguments to base class constructor.
A Optional
B Mandatory
C Compiler dependent
D Error

Answer: Option [B]
10 In Multipath inheritance, in order to remove duplicate set of records in child class, we ___________ .
A Write Virtual function in parent classes
B Write virtual functions is base class
C Make base class as virtual base class
D All of these

Answer: Option [C]
11 In case of inheritance where both base and derived class are having constructor and destructor, then which if the following are true ?

1. Constructors are executed in their order of derivation

2. Constructors are executed in reverse order of derivation

3. Destructors are executed in their order of derivation

4. Destructors are executed in reverse order of derivation

A Only 2 ,4
B Only 1 , 3
C Only 1 , 4
D Only 2, 3

Answer: Option [C]
12 What is the difference between protected and private access specifiers in inheritance?
A private member is not inheritable and not accessible in derived class.
B protected member is inheritable and also accessible in derived class
C Both are inheritable but private is accessible in the derived class
D Both are inheritable but protected is not accessible in the derived class.

Answer: Option [B]
13
A call by value
B call by reference
C call by pointer
D none of the mentioned

Answer: Option [B]
14 When a child class inherits traits from more than one parent class, this type of inheritance is called _______________ inheritance.
A Hierarchical
B Hybrid
C Multilevel
D Multiple

Answer: Option [D]
15 Constant function in C++ can be declared as
A void display()
B void display() const
C const void display()
D void const display()

Answer: Option [B]
16 True and false statements about inline function in given C++ code example is/are

(I)Static function of a class can be called by class name using scope resolution operator i.e. : :

(II)Static function can receive both static and non-static data members of a class

(III)Static function is not the part of an object of a class

A I and II
B I only
C I and III
D I, II and III

Answer: Option [C]
17 Which of the following functions are provided by compiler by default if we don’t write in a C++ class?
A Copy constructor
B Assignment
C Constructor
D All the above

Answer: Option [B]
18 When our function doesn’t need to return anything means what we will as parameter in function?
A void
B blank space
C both a & b
D none of the mentioned

Answer: Option [B]
19 Which function can be called without using an object of a class in C++
A Static function
B Inline function
C Friend function
D constant function

Answer: Option [A]
20 Which function can be called without using an object of a class in C++
A Virtual function
B Inline function
C Static function
D constant function

Answer: Option [C]