-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16.classes.py
More file actions
58 lines (44 loc) · 1.49 KB
/
16.classes.py
File metadata and controls
58 lines (44 loc) · 1.49 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
# Classes are blueprint of objects
class Vehicle:
def __init__(self, make, model):
self.make = make
self.model = model
def moves(self):
print(f"Moves along with make of {self.make} and model {self.model}")
def get_Make_Model(self):
print(f"I'm a {self.make} {self.model}")
mycar = Vehicle("Hyundai","Verna")
# print("Make of my car is:", mycar.make)
# print(f"Model of my car is: {mycar.model}")
mycar.get_Make_Model()
mycar.moves()
newCar = Vehicle("Ford","Mustang")
newCar.get_Make_Model()
newCar.moves()
class AeroPlane(Vehicle):
def __init__(self, make, model,faa_id):
# Super with parameter will inherit the values of make and model form parent class
super().__init__(make, model)
self.faa_id = faa_id
def moves(self):
print(f"Flies along... with {self.faa_id}")
class Truck(Vehicle):
def moves(self):
print("Rumble along...")
# Pass is the keyword to inherit all props and methods as it from parent class
class GolfCart(Vehicle):
pass
aeroPlane = AeroPlane("Emirates", "A380", "EK214")
truck = Truck("AL","Truck001")
golfwagon = GolfCart("Golf","GC0001")
aeroPlane.get_Make_Model()
aeroPlane.moves()
truck.get_Make_Model()
truck.moves()
golfwagon.get_Make_Model()
golfwagon.moves()
# Polymorphism is same method return different set of responses
print("Polymorphism".center(100,"*"))
for v in (mycar, newCar, aeroPlane, truck, golfwagon):
v.get_Make_Model()
v.moves()