-
Notifications
You must be signed in to change notification settings - Fork 0
/
Abstraction_Car.py
52 lines (39 loc) · 1.12 KB
/
Abstraction_Car.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
from abc import ABC, abstractmethod
class Car(ABC):
def __init__(self, color):
print("Car constructor called")
self.color = color
@abstractmethod
def speed(self):
pass
@abstractmethod
def __str__(self):
pass
def get_color(self):
return self.color
class Audi(Car):
def __init__(self, color, speed):
super().__init__(color)
print("Audi constructor called")
self.speed_val = speed
def speed(self):
return self.speed_val
def __str__(self):
return "Audi Color: " + self.color + " speed: " + str(self.speed())
class Mercedes(Car):
def __init__(self, color, distance, time):
super().__init__(color)
print("Mercedes constructor called")
self.distance = distance
self.time = time
def speed(self):
return self.distance / self.time
def __str__(self):
return "Mercedes color is " + self.color + " and speed is : " + str(self.speed())
def main():
s1 = Audi("Red", 2.2)
s2 = Mercedes("Yellow", 2, 4)
print(s1)
print(s2)
if __name__ == "__main__":
main()