-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut37.cpp
More file actions
47 lines (45 loc) · 1.09 KB
/
tut37.cpp
File metadata and controls
47 lines (45 loc) · 1.09 KB
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
#include <bits/stdc++.h>
using namespace std;
// base class
class Employee{
public:
int id;
float salary;
Employee(int inpId)
{
id = inpId;
salary = 34.0;
}
Employee(){}
};
// derived class syntax
/*class {{derived-class-name}} : {{visiblity-mode}} {{base-class-name}}
{
class members/methods/etc.....
}
1.private visiblity mode: public members of the derived class become privatre members of the derived class
2.public visiblity mode: public members of the derived class become public members of the derived class
3.private members of a base class are never inherited
*/
// creating a programmer class derived from Employee base class
class Programmer : Employee
{ // default visiblity mode is private
public:
Programmer(int inpId){
id=inpId;
}
int LanguageCode = 9;
void getdata(){
cout<<id<<endl;
}
};
int main()
{
Employee harry(1), rohan(2);
cout << harry.salary << endl;
cout << rohan.salary << endl;
Programmer skillf(1);
cout<<skillf.LanguageCode<<endl;
skillf.getdata();
return 0;
}