forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleInheritance.cpp
More file actions
57 lines (49 loc) · 866 Bytes
/
singleInheritance.cpp
File metadata and controls
57 lines (49 loc) · 866 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
57
#include<iostream>
using namespace std;
class Base{
private:
int data1;
public:
int data2;
int data3;
void setData()
{
data1 =10;
data2 =20;
}
int getData1();
int getData2();
};
int Base :: getData1()
{
return data1;
}
int Base :: getData2()
{
return data2;
}
//DERIVED CLASS
class Derived : private Base{
int data3;
public:
void multiplyer();
void display();
};
void Derived :: multiplyer(void)
{
setData();
data3 = data2 * getData1();
}
void Derived :: display(void)
{
cout<<"The value of data1 is :"<<getData1()<<endl;
cout<<"The value of data2 is :"<<data2<<endl;
cout<<"The value of data3 is :"<<data3<<endl;
}
int main()
{
Derived num;
num.multiplyer();
num.display();
return 0;
}