Inheritance in C ++ Programming MCQ Questions and Answers

Q1. Which type of inheritance allows a class to inherit from more than one base class?
A) Single Inheritance
B) Multilevel Inheritance
C) Multiple Inheritance
D) Hierarchical Inheritance
Answer: C

Q2. When a derived class inherits from a single base class, it is known as:
A) Single Inheritance
B) Multiple Inheritance
C) Multilevel Inheritance
D) Hybrid Inheritance
Answer: A

Q3. In C++, the keyword used to specify inheritance is:
A) derived
B) class
C) public / private / protected
D) super
Answer: C

Q4. Which access specifier ensures that public members of a base class become private in the derived class?
A) Public
B) Protected
C) Private
D) Default
Answer: C

Q5. Which among the following inheritance types can lead to the diamond problem?
A) Multilevel
B) Single
C) Multiple
D) Hierarchical
Answer: C

Q6. Virtual base classes are primarily used to resolve:
A) Access violations
B) Ambiguity in multiple inheritance
C) Memory leaks
D) Function overriding
Answer: B

Q7. In C++, the constructors of base classes are called in which order?
A) Random order
B) In the order of inheritance declaration
C) Alphabetical order
D) Reverse order
Answer: B

Q8. If a class inherits from multiple base classes, the destructors are executed in which order?
A) Random order
B) Reverse order of constructor execution
C) Same order as constructors
D) None of the above
Answer: B

Q9. Which inheritance type involves more than one level of derivation?
A) Single
B) Multilevel
C) Multiple
D) Hybrid
Answer: B

Q10. The relationship represented by inheritance is best described as:
A) IS-A relationship
B) HAS-A relationship
C) USES-A relationship
D) BELONGS-TO relationship
Answer: A

Q11. What happens when a derived class object is created?
A) Only derived constructor is called
B) Base constructor is called first, then derived constructor
C) Derived constructor first, then base constructor
D) None
Answer: B

Q12. Which of the following is not a valid type of inheritance in C++?
A) Single
B) Multiple
C) Multilevel
D) Parallel
Answer: D

Q13. The default inheritance access specifier for a class in C++ is:
A) Public
B) Private
C) Protected
D) None
Answer: B

Q14. Which type of inheritance combines more than one type of basic inheritance?
A) Single
B) Multilevel
C) Hybrid
D) Multiple
Answer: C

Q15. When base and derived classes have functions with the same name, it is called:
A) Function overloading
B) Function overriding
C) Function hiding
D) Function masking
Answer: B

Q16. Which of the following inheritance types may cause ambiguity in member resolution?
A) Single
B) Multilevel
C) Multiple
D) Hierarchical
Answer: C

Q17. The keyword virtual in base class declaration ensures:
A) Constructor is virtual
B) Only one copy of base class is inherited
C) Faster function calls
D) Abstract base class creation
Answer: B

Q18. Which access specifier allows derived classes to access members but not outside classes?
A) Public
B) Private
C) Protected
D) Default
Answer: C

Q19. In inheritance, base class constructors cannot be:
A) Overloaded
B) Inherited
C) Defined
D) Called
Answer: B

Q20. Which of the following is not inherited by derived classes in C++?
A) Data members
B) Member functions
C) Constructors
D) Static members
Answer: C

Q21. When an object of derived class is assigned to a base class variable, what happens?
A) All members are copied
B) Object slicing occurs
C) Implicit conversion error
D) None of the above
Answer: B

Q22. If class B is derived from class A publicly, then public members of A become:
A) Private in B
B) Public in B
C) Protected in B
D) None
Answer: B

Q23. When inheritance is done privately, what happens to base class public members?
A) Remain public
B) Become private in derived class
C) Become protected
D) Inaccessible
Answer: B

Q24. Virtual inheritance is specified using which keyword?
A) Inherit
B) Derived
C) virtual
D) static
Answer: C

Q25. Which statement about destructors in inheritance is true?
A) Base destructors are never called
B) Destructors are called in reverse order of construction
C) Destructors are called before constructors
D) None
Answer: B

Q26. Which of the following inheritance types allows code reusability but can introduce complexity?
A) Single
B) Multiple
C) Multilevel
D) Hierarchical
Answer: B

Q27. In hybrid inheritance, which C++ feature is required to avoid ambiguity?
A) Templates
B) Virtual base classes
C) Friend functions
D) Operator overloading
Answer: B

Q28. When a derived class function hides a base class function, this is called:
A) Function overloading
B) Function hiding
C) Function overriding
D) Function redeclaration
Answer: B

Q29. Which of the following can’t be inherited?
A) Member functions
B) Constructors and destructors
C) Variables
D) Operators
Answer: B

Q30. Which of the following defines the visibility of inherited members?
A) Access specifiers
B) Scope resolution operator
C) Function overriding
D) Static members
Answer: A

Q31. What is the main advantage of inheritance in C++?
A) Increased compilation time
B) Code reusability
C) Reduced security
D) Better runtime
Answer: B

Q32. In C++, protected members of a base class are accessible to:
A) Only within the base class
B) Derived classes and friends
C) Everyone
D) None
Answer: B

Q33. If class B is privately derived from class A, then public members of A are accessible as:
A) Public
B) Protected
C) Private
D) None
Answer: C

Q34. In case of multiple inheritance, if two base classes have same function name, ambiguity is resolved by:
A) Compiler
B) Scope resolution operator
C) Virtual inheritance
D) Function overriding
Answer: B

Q35. Which of the following is an example of hybrid inheritance?
A) Single + Multiple
B) Multiple + Multilevel
C) Hierarchical + Multilevel
D) Any combination of two or more inheritance types
Answer: D

Q36. Which inheritance type represents a tree-like class hierarchy?
A) Multiple
B) Multilevel
C) Hierarchical
D) Hybrid
Answer: C

Q37. When the base class pointer points to a derived class object, it demonstrates:
A) Overloading
B) Polymorphism
C) Encapsulation
D) Inheritance
Answer: B

Q38. Which among the following cannot be virtual?
A) Member functions
B) Constructors
C) Destructors
D) Static members
Answer: B

Q39. Which inheritance model supports runtime polymorphism?
A) Static
B) Virtual inheritance
C) Multiple
D) Multilevel
Answer: B

Q40. What will happen if we inherit privately and try to access public base members outside?
A) Accessible
B) Not accessible
C) Compile-time warning
D) Runtime error
Answer: B

Q41. Which inheritance allows different classes to share a common base class?
A) Multiple
B) Hierarchical
C) Multilevel
D) Hybrid
Answer: B

Q42. If a base class has a virtual destructor, then:
A) Destructor is not called
B) Derived class destructor will be called first
C) Destructor becomes inline
D) Destructor is hidden
Answer: B

Q43. In C++, when the same member exists in both base and derived class, it can be accessed using:
A) This pointer
B) Scope resolution operator (::)
C) Type casting
D) Friend function
Answer: B

Q44. Which inheritance can cause a diamond-shaped hierarchy?
A) Single
B) Multilevel
C) Multiple
D) Hybrid
Answer: C

Q45. What is the use of the “virtual” keyword in inheritance?
A) Makes a class abstract
B) Ensures only one instance of a base class is inherited
C) Prevents inheritance
D) Creates an interface
Answer: B

Q46. Which of the following types of inheritance is not directly supported by C++?
A) Single
B) Multiple
C) Multilevel
D) Cyclic inheritance
Answer: D

Q47. Which of the following relationships is not represented by inheritance?
A) Student IS-A Person
B) Manager IS-A Employee
C) Car HAS-A Engine
D) Bird IS-A Animal
Answer: C

Q48. When a base class function is made virtual, the decision to call it is made:
A) At compile time
B) At runtime
C) During linking
D) By the preprocessor
Answer: B

Q49. What is the main disadvantage of multiple inheritance?
A) Slow performance
B) Ambiguity and complexity
C) Larger object size
D) Lack of polymorphism
Answer: B

Q50. The order of calling destructors in inheritance is:
A) Derived to base
B) Reverse of constructor order (derived → base)
C) Base to derived
D) Random
Answer: B

Q51. When we inherit publicly, private members of the base class become:
A) Public
B) Protected
C) Inaccessible
D) Private
Answer: C

Q52. Which keyword is used to prevent a class from being inherited further?
A) static
B) private
C) final
D) sealed
Answer: C

Q53. In multiple inheritance, constructors of base classes are called in:
A) Reverse order
B) Order of declaration
C) Alphabetical order
D) None
Answer: B

Q54. Which inheritance type can simulate interface-like behavior in C++?
A) Hierarchical
B) Multiple
C) Hybrid
D) Multilevel
Answer: B

Q55. If two base classes contain the same member function, which one is called by default?
A) Last base class
B) Ambiguity occurs
C) First base class
D) None
Answer: B

Q56. Which of the following inheritance types can have more than one direct base class?
A) Single
B) Multiple
C) Multilevel
D) Hierarchical
Answer: B

Q57. If class B is derived from class A, and class C is derived from B, this is an example of:
A) Multiple
B) Multilevel inheritance
C) Hierarchical
D) Hybrid
Answer: B

Q58. What will be inherited if the base class members are declared private?
A) They are not inherited directly
B) Inherited as private
C) Inherited as protected
D) Inherited as public
Answer: A

Q59. What happens if a derived class defines a function with the same name as a base class but different parameters?
A) Function overloading
B) Function overriding
C) Function hiding
D) Compilation error
Answer: A

Q60. Which inheritance model is used to eliminate redundancy in hybrid inheritance?
A) Single
B) Multiple
C) Virtual inheritance
D) Multilevel
Answer: C

Q61. What does the term “base class” mean?
A) A class whose properties are inherited
B) A class that cannot be derived
C) A class derived from another
D) None
Answer: A

Q62. A class derived from two base classes that share a common ancestor represents:
A) Multilevel
B) Diamond inheritance
C) Hierarchical
D) Hybrid
Answer: B

Q63. In inheritance, a base class function made private is:
A) Not accessible in derived class
B) Accessible through pointer
C) Overridable
D) Automatically public
Answer: A

Q64. Virtual inheritance helps to:
A) Increase memory usage
B) Reduce speed
C) Avoid duplicate copies of base class
D) Hide members
Answer: C

Q65. What is the purpose of inheritance in OOP?
A) To duplicate code
B) To restrict access
C) To promote code reuse and extensibility
D) To increase complexity
Answer: C

Q66. Which inheritance type results in a single derived class from multiple bases?
A) Multiple
B) Hierarchical
C) Multilevel
D) Hybrid
Answer: A

Q67. Which inheritance can simulate a class hierarchy like “Animal → Mammal → Dog”?
A) Multiple
B) Multilevel
C) Hybrid
D) Hierarchical
Answer: B

Q68. Which of the following prevents ambiguity in multiple inheritance?
A) Virtual base class
B) Static function
C) Abstract function
D) Overloading
Answer: A

Q69. When an object of derived class is destroyed, destructors are called in which order?
A) Base to derived
B) Derived to base
C) Random
D) None
Answer: B

Q70. If class B is publicly derived from A, which of the following is true?
A) Private members of A become public
B) Protected members of A remain protected in B
C) Public members of A become private in B
D) All members become protected
Answer: B

Q71. In inheritance, the base class’s private members are accessible via:
A) Derived class
B) Public/protected member functions of base class
C) Virtual inheritance
D) Not accessible
Answer: B

Q72. When a derived class redefines a base class virtual function, it is known as:
A) Function hiding
B) Overriding
C) Overloading
D) Shadowing
Answer: B

Q73. What is the output when a derived class overrides a base class virtual function and is called via base pointer?
A) Base function called
B) Derived function called
C) Compile error
D) None
Answer: B

Q74. Which feature of inheritance supports dynamic binding?
A) Static functions
B) Virtual functions
C) Templates
D) Operator overloading
Answer: B

Q75. What happens if a virtual base class constructor takes arguments?
A) Compiler error
B) Derived constructor must explicitly call it
C) Automatically initialized
D) Ignored
Answer: B

Q76. Which inheritance makes all base class members private by default?
A) Public
B) Protected
C) Private inheritance
D) Multiple
Answer: C

Q77. What is meant by “hierarchical inheritance”?
A) One base class, many derived classes
B) One derived, many bases
C) Multilevel
D) None
Answer: A

Q78. When do we use virtual base classes?
A) To hide members
B) To resolve diamond inheritance ambiguity
C) To create templates
D) To restrict polymorphism
Answer: B

Q79. Can a derived class override a non-virtual base function?
A) Yes
B) No
C) Only if protected
D) Only with inline
Answer: B

Q80. Which of the following can access private members of a base class?
A) Derived class
B) Friend function of base class
C) Any class
D) None
Answer: B

Q81. If a derived class has no constructors, what happens when it is instantiated?
A) Error
B) Base class default constructor is called
C) No constructor called
D) Undefined behavior
Answer: B

Q82. When inheritance uses the “protected” specifier, base public members become:
A) Public
B) Protected
C) Private
D) Hidden
Answer: B

Q83. Which of these is an example of hierarchical inheritance?
A) Class A → B, A → C
B) A → B → C
C) B, C → D
D) A, B → C
Answer: A

Q84. Which inheritance type can be represented as a diamond diagram?
A) Hybrid inheritance
B) Single
C) Multilevel
D) Hierarchical
Answer: A

Q85. What ensures that only one instance of a base class is inherited in multiple inheritance?
A) Static inheritance
B) Virtual inheritance
C) Friend functions
D) Templates
Answer: B

Q86. Which feature of C++ prevents object slicing?
A) Multiple inheritance
B) Using pointers or references to base class
C) Private inheritance
D) Friend functions
Answer: B

Q87. Which type of inheritance is demonstrated when one derived class inherits from two unrelated base classes?
A) Multiple inheritance
B) Hierarchical
C) Multilevel
D) Hybrid
Answer: A

Q88. What happens if a class inherits privately from multiple base classes?
A) All members become public
B) All inherited members become private
C) Error
D) Protected
Answer: B

Q89. Which inheritance helps in implementing interfaces conceptually in C++?
A) Multilevel
B) Multiple inheritance using pure virtual classes
C) Hybrid
D) Single
Answer: B

Q90. In the diamond problem, ambiguity arises because:
A) Derived class hides base class
B) Two paths lead to same base class member
C) Constructors conflict
D) Compiler cannot link
Answer: B

Q91. If class D inherits from both B and C, and both inherit from A, this is:
A) Hierarchical
B) Hybrid inheritance
C) Multilevel
D) Multiple
Answer: B

Q92. Can constructors be virtual in C++?
A) Yes
B) No
C) Only static
D) Only inline
Answer: B

Q93. The syntax for declaring virtual inheritance is:
A) class Derived : public Base
B) class Derived : virtual public Base
C) class Derived : virtual Base
D) class Derived virtual Base
Answer: B

Q94. Which is true about virtual base classes?
A) They cannot have constructors
B) They avoid duplication in diamond inheritance
C) They cannot be inherited further
D) None
Answer: B

Q95. Inheritance allows:
A) Code duplication
B) Reusability and extensibility
C) Slower performance
D) None
Answer: B

Q96. When an object of derived class is created, which constructor executes first?
A) Base class constructor
B) Derived class constructor
C) Random order
D) None
Answer: A

Q97. Which function is called automatically when an object goes out of scope in inheritance?
A) Constructor
B) Destructor
C) Virtual function
D) Operator=
Answer: B

Q98. Can a class be derived from multiple virtual base classes?
A) No
B) Yes
C) Only if protected
D) Only using templates
Answer: B

Q99. The keyword virtual used with inheritance affects:
A) Data members
B) Function call resolution and base class sharing
C) Operator overloading
D) Template specialization
Answer: B

Q100. Which statement about inheritance is correct?
A) Constructors are inherited
B) Destructors are not inherited but are called automatically
C) Friend functions are inherited
D) Private members are directly accessible
Answer: B