-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance_types.cpp
More file actions
125 lines (68 loc) · 1.63 KB
/
inheritance_types.cpp
File metadata and controls
125 lines (68 loc) · 1.63 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include<iostream>
using namespace std;
//-------------------Inheritance---------------------------->
class A{
public:
int amount;
string name;
};
class B : public A{ //class B is child class and A is base class .
public:
int milage;
string car_color;
string mdoel;
};
int main(){
B car1; //obj of derivd class
car1.amount =90000; //access to base class member.
car1.mdoel = "tyota"; //access to their own member.
}
//-----------------------------Multilevel-inheritance-------------------------------------->
a class derive from another
derived class -> multilevel.
class A{
public:
int roll_no;
string name;
};
class B : public A{ //B is derived from A itself.
public:
string department_name;
int semester;
string subjec;
};
class C : public B{ //C is derivd from another derived class which is B.
public:
string extra_course;
int fee;
int duration;
int course_code;
};
int main(){ //access to both classes define above.
C aa;
aa.name "Mr.Noormast";
aa.department_name = "CS";
aa.subjec = "cs";
}
//-------------------------Multiple-inheritance--------------------------------->
class A{ //Base class
public :
int n;
int m;
};
class B{ //another Base class
public :
string name;
int age;
};
class C : public A, public B{ //derived from A as well as B
public:
int price;
string result;
};
int main(){
C aa;
aa.m = 90;
aa.age = 33;
aa.price = 12944; //access to three classes dierectly its multiple inheritance.
}