#include <iostream> using namespace std; // Base class class Device { public: void showType() { cout << "Generic Device" << endl; } }; // Derived class with protected inheritance class Sensor : protected Device { public: void showSensor() { showType(); // Can access showType() because inheritance is protected cout << "Sensor Device" << endl; } }; int main() { Sensor s; s.showSensor(); // Can call only showSensor(), not showType() directly return 0; }
Test Cases
Test Results
Input
Expected Output
Generic Device Sensor Device