-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.3.py
More file actions
46 lines (35 loc) · 1015 Bytes
/
Copy path3.3.py
File metadata and controls
46 lines (35 loc) · 1015 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
35
36
37
38
39
40
41
42
43
44
45
46
#Inheritance
class Car: #parent class
def print_car_name(self):
print("This is a Car")
return "Nothing"
class Sedan(Car): #Child class
def print_model_name(self):
print("This is the Brand")
return "Nothing"
def print_car_name(self): #method override
print("Well , i am trying to override the car....")
return "Something which is not polluted..."
buy = Sedan()
print(buy.print_car_name())
print(buy.print_model_name())
#polymorphism
class Car:
def drive(self):
print("ok,so i am still driving a car ")
return "CNG"
def accident(self):
print("i got crashed")
return "Hospital bills"
class Truck:
def drive(self): #Overloading
print("I am driving too")
return "Smoke"
def accident(self): #Overloading
print("i am kinda crashing others")
car = Car()
truck = Truck()
print(car.drive)
print(car.accident)
print(truck.drive)
print(truck.accident)