-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessSpecifier.cpp
More file actions
74 lines (64 loc) · 1.41 KB
/
Copy pathAccessSpecifier.cpp
File metadata and controls
74 lines (64 loc) · 1.41 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Write a program to implement the use of access Specifier
#include<iostream>
using namespace std;
// Public Access Specifier
class A
{
public:
int num1, num2;
int add()
{
return num1 + num2;
}
};
// Protected Access Specifier
class B
{
protected:
int num1 = 10, num2 = 20;
public:
int add()
{
return num1 + num2;
}
};
// Private Access Specifier
class C
{
private:
int num1 = 10, num2 = 20;
public:
int add()
{
return num1 + num2;
}
};
int main()
{
//Public
cout<<"Useing Public Access Specifier "<<endl;
A a;
a.num1 = 15;
a.num2 = 20;
cout<<"Num1 : "<<a.num1<<"\nNum2 : "<<a.num2<<"\nSum : " <<a.add()<<endl;
cout<<"-------------***********-------------------"<<endl;
//Protected
cout<<"Useing Protected Access Specifier "<<endl;
B b;
/**----------Not Accessable
a.num1 = 15;
a.num2 = 20;
----------------------**/
cout<<"\nSum : " <<b.add()<<endl;
cout<<"-------------***********-------------------"<<endl;
//Private
cout<<"Useing Private Access Specifier "<<endl;
C c;
/**----------Not Accessable
a.num1 = 15;
a.num2 = 20;
-----------*/
cout<<"\nSum : " <<c.add()<<endl;
cout<<"-------------***********-------------------"<<endl;
return 0;
}