This repository was archived by the owner on Dec 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise44.py
More file actions
70 lines (49 loc) · 1.33 KB
/
Exercise44.py
File metadata and controls
70 lines (49 loc) · 1.33 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
#Exercise 44
class Parent(object):
def __init__(self, stuff):
self.stuff = stuff + " Parent"
print(self.stuff)
def implicit(self):
print("PARENT implicit()")
def override(self):
print("PARENT override()")
def altered(self):
print("PARENT altered()")
class Child(Parent):
def __init__(self, stuff):
#inheritance
self.stuff = stuff
print(self.stuff)
super(Child, self).__init__("Child")
print(self.stuff)
#composition
self.other = Other()
def implicit(self):
#composition
self.other.implicit()
def override(self):
print("CHILD override()")
def altered(self):
#Inheritance using super
print("CHILD BEFORE PARENT altered()")
super(Child, self).altered()
print("CHILD, AFTER PARENT altered()")
print("\n")
print("CHILD BEFORE OTHER altered()")
self.other.altered()
print("CHILD, AFTER OTHER altered()")
class Other(object):
def override(self):
print("OTHER override()")
def implicit(self):
print("OTHER implicit()")
def altered(self):
print("OTHER altered()")
dad = Parent("Parent")
son = Child("Child")
dad.implicit()
son.implicit()
dad.override()
son.override()
dad.altered()
son.altered()