21. Private Inheritance

Your task is to define two classes:

  • Base class: Device
    • Has a public method void showType() that prints:
      Generic Device
       
  • Derived class: Actuator (inherits privately from Device)
    • Has a public method void showActuator() that:
      1. Calls showType() (accessible inside because of inheritance).
      2. Prints:
        Actuator Device


The program will:

  1. Create an Actuator object.
  2. Call only showActuator()showType() is completely hidden from outside.
     

Example

Output:

Generic Device
Actuator Device

 

Why this output?

Because showType() becomes private when inherited, so only the Actuator itself can use it, not even further derived classes.

 

Question Significance

Demonstrates private inheritance, where base methods become private members in the derived class.

 

Loading...

Input

Expected Output

Generic Device Actuator Device