-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessSpecifier.cpp
More file actions
56 lines (47 loc) · 933 Bytes
/
Copy pathAccessSpecifier.cpp
File metadata and controls
56 lines (47 loc) · 933 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
50
51
52
53
54
55
56
#include<iostream>
using namespace std;
class Base // 12
{
public:
int i;
private:
int j;
protected:
int k;
public:
Base()
{
i = 10; j = 20; k = 30;
}
void fun()
{
cout<<i<<"\n"; // Allowed
cout<<j<<"\n"; // Allowed
cout<<k<<"\n"; // Allowed
}
};
class Derived : public Base // 16
{
public:
int x;
void Display()
{
cout<<i<<"\n"; // Allowed
cout<<j<<"\n"; // Error
cout<<k<<"\n"; // Allowed
}
};
int main()
{
Base bobj;
Derived dobj;
cout<<bobj.i<<"\n"; // Allowed
cout<<bobj.j<<"\n"; // Error
cout<<bobj.k<<"\n"; // Error
cout<<dobj.i<<"\n"; // Allowed
cout<<dobj.j<<"\n"; // Error
cout<<dobj.k<<"\n"; // Error
dobj.fun(); // Allowed
dobj.Display(); // Allowed
return 0;
}