-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class-Coding-Inheritance.py
193 lines (145 loc) · 3.95 KB
/
Class-Coding-Inheritance.py
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
class Animal:
"""Animal Class"""
def __init__(self, name):
print("Initializing name")
self.__name = name
@property
def name(self):
print("Getting name")
return self.__name
@name.setter
def name(self, new_name):
print("Setting name")
self.__name = new_name
@name.deleter
def name(self):
print("Deleting name")
del self.__name
def move(self):
print("Moving")
def eat(self):
print("Eating")
def sleep(self):
print("Sleeping")
class Fish(Animal):
def swim(self):
print("Swimming")
class Snake(Animal):
def hiss(self):
print("Hissing")
class Person(Animal):
def talk(self):
print("Talking")
class Book:
"""Book Class"""
def __init__(self, title):
print("Initializing title")
self.__title = title
@property
def title(self):
print("Getting title")
return self.__title
@title.setter
def title(self, new_title):
print("Setting title")
self.__title = new_title
@title.deleter
def title(self):
print("Deleting title")
del self.__title
def __init__(self, ISBN):
print("Initializing ISBN")
self.__ISBN = ISBN
@property
def ISBN(self):
print("Getting ISBN")
return self.__ISBN
def __init__(self, yearPublished):
print("Initializing year published")
self.__yearPublished = yearPublished
@property
def yearPublished(self):
print("Getting year published")
return self.__yearPublished
def __init__(self, author):
print("Initializing author")
self.__author = author
@property
def author(self):
print("Getting author")
return self.__author
class Textbook(Book):
def study(self):
print("Studying")
class AddressBook(Book):
def search(self):
print("Searching")
class Vehicle:
"""Vehicle class"""
def __init__(self, make):
print("Initializing make")
self.__make = make
@property
def make(self):
print("Getting make")
return self.__make
def __init__(self, model):
print("Initializing model")
self.__model = model
@property
def model(self):
print("Getting model")
return self.__model
def __init__(self, year):
print("Initializing year")
self.__year = year
@property
def year(self):
print("Getting year")
return self.__year
def __init__(self, VIN):
print("Initializing VIN")
self.__VIN = VIN
@property
def VIN(self):
print("Getting VIN")
return self.__VIN
def __init__(self, licensePlate):
print("Initializing license plate")
self.__licensePlate = licensePlate
@property
def licensePlate(self):
print("Getting license plate")
return self.__licensePlate
def accelerate(self):
print("accelerating")
def brake(self):
print("braking")
def turn(self):
print("Turning")
def reverse(self):
print("Reversing")
def radio(self):
print("Playing radio")
def airConditioning(self):
print("Air conditioning on")
def heat(self):
print("Heat is on")
def wipers(self):
print("Wipers are on")
def honk(self):
print("Honking")
def headLights(self):
print("Headlights are on")
class Car(Vehicle):
def drive(self):
print("Driving")
class Bicycle(Vehicle):
def ringBell(self):
print("Ringing bell")
class Boat(Vehicle):
def putUpSail(self):
print("Putting up sail")
class HotAirBalloon(Vehicle):
def float(self):
print("Floating")