-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle_polymorphism.py
More file actions
34 lines (24 loc) · 872 Bytes
/
Copy pathVehicle_polymorphism.py
File metadata and controls
34 lines (24 loc) · 872 Bytes
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
#Write a Python program to create two classes - BMW and Ferrari with similar methods and implement Polymorphism on them.
class BMW:
def start_engine(self):
return "BMW engine started with a smoothhhhhhh roarrrrrr."
def top_speed(self):
return "The BMW has a top speed of 250 km/h."
def price(self):
return "The BMW costs around 1.82 Crore."
class Ferrari:
def start_engine(self):
return "Ferrari engine started with a louddddddddddddd revvvvvvv."
def top_speed(self):
return "The Ferrari has a top speed of 350 km/h."
def price(self):
return "The Ferrari costs around 3.50 Crore"
def car_details(car):
print(car.start_engine())
print(car.top_speed())
print(car.price())
print("-" * 100)
bmw_car = BMW()
ferrari_car = Ferrari()
car_details(bmw_car)
car_details(ferrari_car)