-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathdiamond_problem.py
More file actions
82 lines (60 loc) · 1.71 KB
/
Copy pathdiamond_problem.py
File metadata and controls
82 lines (60 loc) · 1.71 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Parent:
def __init__(self):
self.a = 2
self.b = 4
def print_name(self):
print("parent")
def form1(self):
print("calling parent form1")
print('p', self.a + self.b)
class Child1(Parent):
def __init__(self):
super().__init__()
self.a = 50
self.b = 4
def print_name(self):
print("child1")
def print_super_name(self):
super().print_name()
def form1(self):
print('bye', self.a - self.b)
def callchildform1(self):
print("calling parent from child1")
super().form1()
class Child2(Parent):
def __init__(self):
super().__init__()
self.a = 3
self.b = 4
def print_name(self):
print("child2")
def form1(self):
print('hi', self.a * self.b)
def callchildform1(self):
print("calling parent from child2")
super().form1()
class Grandchild(Child1, Child2):
def __init__(self):
super().__init__()
self.a = 10
self.b = 4
def print_name(self):
print("grandchild")
def print_super_name(self):
super().print_name()
def print_super_super_name(self):
super().print_super_name()
def callingparent(self):
super().form1()
g = Grandchild()
print("When I print the name of my class it is:")
g.print_name()
print("When I print my superclass name, it is:")
g.print_super_name()
print("When I print the name of the superclass of my superclass, it is:")
g.print_super_super_name()
print("When you call methods on me, they will be executed from my class and my parent classes in the following order:")
print(Grandchild.__mro__)
g.form1()
g.callchildform1()
g.callingparent()