22. Multiple Inheritance Sensor and Logger

Your task is to define three classes:

  • Base class 1: Sensor
    • A method void readValue() that prints:
      Reading sensor value
       
  • Base class 2: Logger
    • A method void logData() that prints:
      Logging data
       
  • Derived class: SmartSensor (inherits publicly from both Sensor and Logger)
    • A method void process() that calls both readValue() and logData().
       

The program will:

  1. Create a SmartSensor object.
  2. Call process().

     

Example

Output:

Reading sensor value
Logging data

Why this output?

Because process() calls both base class methods — one from Sensor and one from Logger.

 

Question Significance

This shows how a single class can combine functionality from multiple base classes.

Loading...

Input

Expected Output

Reading sensor value Logging data