cpp inheritance exercise

C++ exercise

1. How many basic types of inheritance are provided as OOP feature ?

a. 4
b. 3
c. 2
d. 1.

Show Answer

The correct option is (a)
Explanation:
There are basically 4 types of inheritance provided in OOP, namely, single level, multilevel, multiple and hierarchical inheritance.

2. Which among the following best defines single level inheritance ?

a. A class inheriting a base class
b. A class inheriting a nested class
c. A class inheriting a derived class
d. A class which gets inherited by 2 classes

Show Answer

The correct option is (a)
Explanation:
A class inheriting a base class defines single level inheritance. Inheriting an already derived class makes it multilevel inheritance. And if base class is inherited by 2 other classes, it is multiple inheritance.

3. Which programming language does not support multiple inheritance?

a. C and C++
b. Java and SmallTalk
c. C++ and Java
d. Java

Show Answer

The correct option is (d)
Explanation:
Java doesn’t support multiple inheritance. But that feature can be implemented by using the interfaces concept

4. Which type of inheritance leads to diamond problem?

a. Multi-level
b. Multiple
c. Hierarchical
d. Multiple

Show Answer

The correct option is (d)
Explanation:
When 2 or more classes inherit the same class using multiple inheritance and then one more class inherits those two base classes, we get a diamond like structure. Here, ambiguity arises when same function gets derived into 2 base classes and finally to 3rd level class because same name functions are being inherited.

5. Which access type data gets derived as private member in derived class?

a. Public
b. Protected
c. Protected and Private
d. Private

Show Answer

The correct option is (d)
Explanation:
It’s rule, that when a derived class inherits the base class with the private access mode, all the data members of base class gets derived as private members of the derived class.

6. Members or class which are not intended to be inherited are declared as ________________

a. Protected members
b. Private members
c. Private or Protected members
d. Public members

Show Answer

The correct option is (b)
Explanation:
Private access modifier is the most secure access mode. It doesn’t allow members or class to be inherited. Even Private inheritance can only inherit protected and public members.

7. base class and derived class relationship comes under ?

a. Polymorphism
b. encapsulation
c. Inheritance
d. None

Show Answer

The correct option is (c)
Explanation:
Base class and derived class come under inheritance, one of the C++ oops principle.

8. C++ Inheritance relationship known ??

a. Has-A
b. Is-A
c. Association
d. None

Show Answer

The correct option is (b)
Explanation:
IS A Relationship is related to inheritance in C++.

9. Inheritance allow in C++ Program?

a. Creating a hierarchy of classes
b. Extendibility
c. Class Re-usability
d. All

Show Answer

The correct option is (d)
Explanation:
Advantage of inheritance are like re-usability- You can re-use existing class in a new class that avoid re-writing same code.

10. If the derived class is struct, then default visibility mode is _______ ?

a. protected
b. public
c. private
d. struct can’t inherit class

Show Answer

The correct option is (b)
Explanation:
No Explanation

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise