-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37singleinherit.cpp
More file actions
54 lines (50 loc) · 1.09 KB
/
Copy path37singleinherit.cpp
File metadata and controls
54 lines (50 loc) · 1.09 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
#include <iostream>
using namespace std;
class base
{
int data1; // private data of base class, not inheritable
public:
int data2;
void setData();
int getData1();
int getData2();
};
void base ::setData()
{
data1 = 10;
data2 = 9;
}
int base ::getData1()
{
return data1;
}
int base ::getData2()
{
return data2;
}
class derived : public base
{
int data3;
public:
void process();
void display();
};
void derived ::process()
{
data3 = data2 * getData1(); // since data1 is not inherited, we can access it through getData1() function that is inherited
}
void derived ::display()
{
cout << "The Value of data1 is : ";
cout << getData1() << endl;
cout << "The Value of data2 is : " << data2 << endl;
cout << "The Value of data3 is : " << data3 << endl;
}
int main()
{
derived d1;
d1.setData(); // if the visibility mode is set to private, we can't directly call this function as it will be private for derived class object
d1.process(); // to acccess above function in private mode, insert it in this to access
d1.display();
return 0;
}