Object Accessing Inherited Variables

#include <iostream>
using namespace std;

class Device {
public:
    int id;
};

class Sensor : public Device {
public:
    int value;
};

int main() {
    Sensor s;
    s.id=101;
    s.value=75;
    printf("Device ID: %d, Sensor Value: %d",s.id,s.value);
    return 0;
}
Upvote
Downvote
Loading...

Input

Expected Output

Device ID: 101, Sensor Value: 75