-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut38_private.cpp
53 lines (44 loc) · 897 Bytes
/
tut38_private.cpp
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
// Single Inheritance Deep Dive : Examples + Code
#include <iostream>
using namespace std;
class Base
{
int data1; // private by default and is not inheritable.
public:
int data2;
void setData();
int getData1();
int getData2();
};
void Base :: setData (void){
data1 = 10;
data2 = 20;
}
int Base :: getData1(){
return data1;
}
int Base :: getData2(){
return data2;
}
class Derived : private Base { // class is being derived privatelly
int data3;
public:
void process();
void display();
};
void Derived :: process(){
setData();
data3 = data2 * getData1();
}
void Derived :: display(){
cout<<"Value of data 1 is "<<getData1()<<endl;
cout<<"Value of data 2 is "<<data2<<endl;
cout<<"Value of data 3 is "<<data3<<endl;
}
int main(){
Derived der;
// der.setData();
der.process();
der.display();
return 0;
}