-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path35Single_Inheritance.cpp
More file actions
59 lines (48 loc) · 1.17 KB
/
Copy path35Single_Inheritance.cpp
File metadata and controls
59 lines (48 loc) · 1.17 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
#include <iostream>
using namespace std;
class base
{
int data1;
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 : public base /* now if we would have derived it as private then we wouldnt be able to call
getdata function in main body of cody, as getdata function will become a private member
of the the class derived and cannot be directly called, but if we put the getData function
in process function, we can call it through process in mainbody.
*/
{
int data3;
public:
void process();
void display();
};
void Derived :: process(){
data3 = data2*getData1();
}
void Derived :: display(){
cout<<"Value of data1 is "<<getData1() <<endl;
cout<<"Value of data1 is "<<data2 <<endl;
cout<<"Value of data1 is "<<data3 <<endl;
}
int main()
{
Derived der;
der.setdata();
der.process();
der.display();
return 0;
}