-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance
More file actions
50 lines (42 loc) · 958 Bytes
/
Inheritance
File metadata and controls
50 lines (42 loc) · 958 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
47
48
49
50
#Single Inheritance
class Car:
color = "black"
@staticmethod
def start():
print("car started..")
@staticmethod
def stop():
print("car stopped..")
class ToyotaCar(Car):
def __init__(self, name):
self.name = name
car1 = ToyotaCar("Fortuner")
car2 = ToyotaCar("prius")
print(car1.color)
#Multi-level Inheritance
class Car:
@staticmethod
def start():
print("car started..")
@staticmethod
def stop():
print("car stopped..")
class ToyotaCar(Car):
def __init__(self, brand):
self.brand = brand
class Fortuner(ToyotaCar):
def __init__(self, type):
self.type = type
car1 = Fortuner("diesel")
car1.start()
#Multiple Inheritance
class A:
varA = "Welcome to class A"
class B:
varB = "Welcome to class B "
class C(A,B):
varC = "Welcome to class C"
c1 = C()
print(c1.varC)
print(c1.varB)
print(c1.varA)