-
Notifications
You must be signed in to change notification settings - Fork 2
/
inheritance.py
66 lines (56 loc) · 1.12 KB
/
inheritance.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Understanding inheritance using classes in python programming language.
#Parent Class
class A(object):
def go(self):
print("go A go!")
def stop(self):
print("stop A stop!")
def pause(self):
raise Exception("Not Implemented")
#Child of A
class B(A):
def go(self):
super(B, self).go()
print("go B go!")
#Child of A
class C(A):
def go(self):
super(C, self).go()
print("go C go!")
def stop(self):
super(C, self).stop()
print("stop C stop!")
#Child of B and C
class D(B,C):
def go(self):
super(D, self).go()
print("go D go!")
def stop(self):
super(D, self).stop()
print("stop D stop!")
def pause(self):
print("wait D wait!")
#Child of B and C
class E(B,C): pass
#creating objects of each class
a = A()
b = B()
c = C()
d = D()
e = E()
# specify output from here onwards, run each command below one by one and try to understand.
a.go()
b.go()
c.go()
d.go()
e.go()
a.stop()
b.stop()
c.stop()
d.stop()
e.stop()
a.pause()
b.pause()
c.pause()
d.pause()
e.pause()