-
Notifications
You must be signed in to change notification settings - Fork 0
/
polypherism.py
35 lines (26 loc) · 861 Bytes
/
polypherism.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
class Car:
def __init__(self, brand, model) -> str:
self.brand = brand
self.model = model
def move(self):
print("Drive")
class Boat:
def __init__(self, brand, model) -> str:
self.brand = brand
self.model = model
def move(self):
print ('sail')
class Plane:
def __init__(self, brand, model) -> str:
self.brand = brand
self.model = model
def move(self):
print("fly")
car1 = Car("Toyota", "Fortuner")
boat1 = Boat("Ibiza", "Touring 20")
plane1 = Plane("Boeing", "747")
car1.move()
boat1.move()
plane1.move()
#Polymorphism is often used in Class methods, where we can have multiple classes with the same method name.
# For example, say we have three classes: Car, Boat, and Plane, and they all have a method called move():