some more content
This commit is contained in:
33
OOP/access_specifier/ex2.cpp
Normal file
33
OOP/access_specifier/ex2.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
Here we have the protected specifier which lets a class inherit a variable (in this example it is salary!)
|
||||
*/
|
||||
|
||||
class Employee {
|
||||
protected:
|
||||
int salary;
|
||||
};
|
||||
|
||||
class Programmer: public Employee {
|
||||
public:
|
||||
int bonus;
|
||||
void setSalary(int s) {
|
||||
salary = s;
|
||||
}
|
||||
int getSalary() {
|
||||
return salary;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Programmer classobj;
|
||||
classobj.setSalary(1000);
|
||||
classobj.bonus = 200;
|
||||
|
||||
cout << "Salary for Programmer Class: " << classobj.getSalary() << "\n";
|
||||
cout << "Bonus for Programmer Class: " << classobj.bonus << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user