class parent(object):
def override1(self):
print("Parent") class child(parent):
def override2(self):
print("Child") dad=parent()
son=child() dad.override1() son.override1() son.override2()
输出结果:
Parent
Parent
Child
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()
运行结果:
Parent altered()
Child,Before Parent altered()
Parent altered()
Child,After Parent altered()