-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut37.cpp
68 lines (61 loc) · 1.46 KB
/
tut37.cpp
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
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
void name()
{
cout << 'Author: Varun Gupta' << endl;
}
class Worker
{
public:
int no;
int name;
Worker(int pop)
{
name = 85;
no = pop;
cout << "This is the value of pop " << no << endl;
}
Worker() {}
void outdata()
{
cout << "This is it " << endl;
}
};
// The syntax :
// class-derived-name : {Visibility-Mode} {Derived-base-name} {};
/* Public visibility mode: The public members of the base class becomes the public members of the derived class.
Private visibility mode: The public members of the base class becomes the private members of the derived class.
By default: Visibility mode is Private.
The private members are never invoked. */
class Transporter : public Worker
{
public:
int Price;
// float Wage;
Transporter(int en)
{
no = en;
Price = 100;
}
void outdata2()
{
cout << "This is the second data \n"
<< no << endl;
}
};
int main()
{
name();
Worker rajesh(2), mahi(6), hari(3);
cout<<"This is name "<<rajesh.name<<endl;
cout<<"This is name "<<mahi.name<<endl;
cout<<"This is name "<<hari.name<<endl;
// hari.name;
Transporter T1(10), t2(20);
// T1.no; is only invoked because the base class is decalared public while initializing.
cout << T1.no << endl;
cout << T1.Price << endl;
// T1.Price;
T1.outdata2();
return 0;
}