-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18_oops.cpp
More file actions
49 lines (45 loc) · 1019 Bytes
/
18_oops.cpp
File metadata and controls
49 lines (45 loc) · 1019 Bytes
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
#include<iostream>
using namespace std;
//Base class
class employee {
public:
int id;
float salary;
employee (int inpId){
id=inpId;
salary =34.0;
}
employee(){}
};
//Derive class syntax
/*
class {{derived-class-name}}:{{visibility-mode}} {{base-case-name}}
{
class members/method/etc...
}
Note:
1. default visibility mode is private
2.public vsibility mode: public member of the base class become public member of the derived class.
3. private vsibility mode: public member of the base class become private member of the derived class.
4. private member never inheritated.
*/
// creating a programmer class derived from employee base class
class programmer : employee{
public:
programmer(int inpId){
id =inpId;
}
int languagecode =9;
void getdata(){
cout<<id<<endl;
}
};
int main(){
employee khushi(1), ritik(2);
cout<<khushi.salary<<endl;
cout<<ritik.salary<<endl;
programmer skillF(1);
cout<<skillF.languagecode<<endl;
skillF.getdata();
return 0;
}