When the inheritance is private, the private methods in base class are...
When the inheritance is private, the private methods in base class are inaccessible in the derived class (in C++). For more information on inheritance Refer:Inheritance in C++ Option (A) is correct.
View all questions of this test
When the inheritance is private, the private methods in base class are...
Inheritance and Access Modifiers in C++:
In C++, the access modifiers (public, protected, and private) define the level of access that a member (variable or function) has in a class. These access modifiers play a crucial role in determining the visibility and accessibility of members in the derived classes.
Private Inheritance and Access Modifiers:
Private inheritance is one of the types of inheritance where the public and protected members of the base class become private in the derived class. This means that the derived class can only access the public and protected members of the base class through its own public and protected members, but it cannot access them directly.
Private Methods in Base Class:
When a method in the base class is declared as private, it means that the method is only accessible within the base class itself. Private methods cannot be accessed by the derived class or any other class outside the base class.
Access to Private Methods in Derived Class:
When a class inherits privately from a base class, all the public and protected members of the base class become private members of the derived class. However, the private members of the base class are not accessible in the derived class. This means that private methods in the base class are inaccessible in the derived class.
Explanation of the Correct Answer:
The correct answer to the given question is option 'A' - inaccessible. This is because when inheritance is private, the private methods in the base class become private members of the derived class. As per the rules of access modifiers, private members are only accessible within the same class and cannot be accessed by any derived class. Hence, the private methods in the base class are inaccessible in the derived class.
In summary, when inheritance is private, the private methods in the base class are inaccessible in the derived class. This is because private members can only be accessed within the same class and are not accessible by any derived class.