-
Notifications
You must be signed in to change notification settings - Fork 0
/
37-inheritance.cpp
58 lines (54 loc) · 1.22 KB
/
37-inheritance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
// Base Class.
class employee
{
public:
int id;
float salary;
employee() {} // This default constructor is used for inheritance.
employee(int inpId)
{
id = inpId;
salary = 34;
}
};
/*
Derived Class Synatax:-
class {{derived-class-name}} : {{visibility-mode}} {{base-class-name}} // "{{}}" --> Things to be replaced.
{
members, methods, etc...
}
Note:-
1) Visibility mode are of two types:-
a) Private: Public members of the base class becomes private members of the derived class.
b) Public: Public members of the base class becomes public members of the derived class.
2) Default visibility mode is private.
3) Private members of base class are never inherited.
*/
// Derived Class.
class programmer : public employee
{
public:
int language_code;
programmer(int inp_id)
{
id = inp_id;
language_code = 9;
}
void get_data()
{
cout << id << "\n";
}
};
int main()
{
employee aditya(1), manoj(2);
cout << aditya.salary << "\n";
cout << manoj.salary << "\n";
programmer skillF(10);
cout << skillF.language_code << "\n";
cout << skillF.id << "\n";
skillF.get_data();
return 0;
}