forked from 521xueweihan/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex44c.py
More file actions
26 lines (19 loc) · 570 Bytes
/
ex44c.py
File metadata and controls
26 lines (19 loc) · 570 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
#coding:utf-8
#################
# 习题44c:继承--在运行前或运行后替换
#################
# 前言
# 第三种方法是一个覆盖的特例,你想在父类中定义的内容运行之前
# 或之后再修改行为。
class Parent(object):
def altered(self):
print "PARENT altered()"
class Child(Parent):
def altered(self):
print "CHILD, BEFORE PARENT altered()"
super(Child, self).altered()
print "CHILD, AFTER PARENT altered()"
dad = Parent()
son = Child()
dad.altered()
son.altered()