-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleInheritance.cpp
More file actions
60 lines (47 loc) · 894 Bytes
/
SingleInheritance.cpp
File metadata and controls
60 lines (47 loc) · 894 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
58
59
60
#include<iostream>
using namespace std;
class Base{
int data1;
public:
int data2;
void setdata();
int getdata1();
int getdata2();
};
void Base :: setdata(void){
data1 = 12;
data2 = 24;
}
int Base :: getdata1(){
return data1;
}
int Base :: getdata2(){
return data2;
}
class Derived : public Base{
int data3;
public:
void Process();
void Display();
};
void Derived :: Process(void){
data3 = data2 * getdata1();
}
void Derived :: Display(){
cout<<"The Value of data 1 is "<< getdata1() <<endl;
cout<<"The Value of data 2 is "<< data2 <<endl;
cout<<"The Value of data 3 is "<< data3 <<endl;
}
int main(){
Derived der;
der.setdata();
der.Process();
der.Display();
return 0;
}
/*
Output :
The Value of data 1 is 12
The Value of data 2 is 24
The Value of data 3 is 288
*/