-
Notifications
You must be signed in to change notification settings - Fork 1
/
13_inheritance.dart
76 lines (54 loc) · 1.38 KB
/
13_inheritance.dart
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
void main(){
// Creating an instance of President and calling the 'role' method
President president = President(name: "Anokhi");
president.role();
VicePresident vicepresident = VicePresident(name: "Saumya");
vicepresident.role();
TechincalLead technicallead = TechincalLead(name: "Dhyan");
technicallead.role();
Executives treasurer = Treasurer(name: "Diya");
(treasurer as Treasurer).role(); // Casting Executives to Treasurer to access its 'role' method
}
class Executives{
void role(){
print("Your role: ");
}
}
class President extends Executives{
String? name;
President({this.name}){
// Calling the role method from Executives class
super.role();
}
// Overriding the role method to print a custom message for President
void role(){
print("Handles and manages all departments.");
}
}
class VicePresident extends Executives{
String? name;
VicePresident({this.name}){
super.role();
}
void role(){
print("Works with other officials to execute permission related tasks");
}
}
class TechincalLead extends Executives{
String? name;
TechincalLead({this.name}){
super.role();
}
void role(){
print("Handles all tech event and workshops.");
}
}
class Treasurer extends Executives{
String? name;
Treasurer({this.name}){
super.role();
}
void role(){
print("Manages money related stuff.");
}
}