-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_oops.cpp
More file actions
42 lines (35 loc) · 1.05 KB
/
04_oops.cpp
File metadata and controls
42 lines (35 loc) · 1.05 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
#include<iostream>
using namespace std;
class Employee {
int id;
static int count;
public:
void setdata(void){
cout<< "enter the id"<<endl;
cin>>id;
count++;
}
void getdata(void){
cout<<"the id of this employee is = "<< id <<" " << "and this is employee number is =" << " " <<count<<endl;
}
//static function
static void getcount(void){
// cout<<id; show error
cout<<"the value of count is ="<< " "<<count<<endl;
}
};
int Employee::count; //defoult value is zero //if we want to start count from 1000 then here we write (int Employee::count 1000;)
int main() {
//count is ststic data member of class employee
Employee khushi,rohan,lovish;
khushi.setdata();
khushi.getdata();
Employee::getcount();
rohan.setdata();
rohan.getdata();
Employee::getcount();
lovish.setdata();
lovish.getdata();
Employee::getcount();//because the static function belongs to the class, not to any specific object like khushi or rohan. so we can call through class , not through any single object
return 0;
}