-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut38.cpp
More file actions
50 lines (41 loc) · 997 Bytes
/
tut38.cpp
File metadata and controls
50 lines (41 loc) · 997 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
#include<bits/stdc++.h>
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(void){
return data1;
}
int Base ::getdata2(void){
return data2;
}
class derived: public Base{
int data3;
public:
void process();
void display();
};
void derived:: process(){
data3=data2=getdata1();
}
void derived:: display(){
cout<<"values of data 1 is "<<getdata1()<<endl;
cout<<"values of data 2 is "<<data2<<endl;
cout<<"values of data 3 is "<<data3<<endl;
}
int main(){
derived der;
der.setData();//if you derive it privately then you won't be able to use it as it will then be a private function of the class derived. You have to use it inside another function in class derived and use that function in public type
der.process();
der.display();
return 0;
}