运行 ❯
获取您
自己的
网站
×
更改方向
更改主题,深色/浅色
转到 Spaces
#include <iostream> using namespace std; // Base class class Employee { protected: // Protected access specifier int salary; }; // Derived class class Programmer: public Employee { public: int bonus; void setSalary(int s) { salary = s; } int getSalary() { return salary; } }; int main() { Programmer myObj; myObj.setSalary(50000); myObj.bonus = 15000; cout << "Salary: " << myObj.getSalary() << "\n"; cout << "Bonus: " << myObj.bonus << "\n"; return 0; }
工资:50000
奖金:15000