-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path38protectedmode.cpp
More file actions
36 lines (31 loc) · 888 Bytes
/
Copy path38protectedmode.cpp
File metadata and controls
36 lines (31 loc) · 888 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
#include <iostream>
using namespace std;
class base
{
// What is protected mode or member?
// protected members are the members that act similar to private members but can be inherited, i.e. they can't be accessed but inherited
protected:
int a;
private:
int b;
};
class derived : protected base
{
int c;
public:
};
/*
Table of mode and derivation
MODE | Private Derivation | Public Derivation | Protected Derivation
Private | not inherited | not inherited | not inherited
Public | private | public | protected
Protected | private | protected | protected
*/
int main()
{
base k;
cout << k.a; // here a can't be accessed as it is protected
derived j;
cout << j.a; // even in derived class, a can't be accessed as it is protected
return 0;
}