-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic.cpp
More file actions
42 lines (30 loc) · 727 Bytes
/
Static.cpp
File metadata and controls
42 lines (30 loc) · 727 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
#include<iostream>
using namespace std;
class Math{
private:
int n1,n2;
public:
Math(){
n1=10;
n2=20;
}
Math(int n1, int n2){
this->n1=n1;
this->n2=n2;
}
void add(){ //non static member function
cout<<"Addition = "<<this->n1+this->n2<<endl;
}
static void sum(int n1, int n2){
int res=n1+n2;
cout<<"Result = "<<res<<endl;
}
};
int main(){
Math m;
m.add();
Math m1(40,50);
m1.add();
Math::sum(70,30); //scope resolution is used to call static member function
return 0;
}