forked from anumsh/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance_interview_question.py
More file actions
68 lines (58 loc) · 984 Bytes
/
inheritance_interview_question.py
File metadata and controls
68 lines (58 loc) · 984 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Inheritance interview questions
class A(object):
def go(self):
print("go A go!")
def stop(self):
print("stop A stop!")
def pause(self):
raise Exception("Not Implemented")
class B(A):
def go(self):
super(B, self).go()
print("go B go!")
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!")
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!")
class E(B,C): pass
a = A()
b = B()
c = C()
d = D()
e = E()
"""
output:
go A go!
go A go!
go B go!
go A go!
go C go!
go A go!
go C go!
go B go!
go D go!
go A go!
go C go!
go B go!
stop A stop!
stop A stop!
stop A stop!
stop C stop!
stop A stop!
stop C stop!
stop D stop!
stop A stop!
stop C stop!
"""