Exercise 44a - inheritance
class Parent(object):
def implicity(self):
print("PARENT implicity()")
class Child(Parent):
pass
dad = Parent()
son = Child()
dad.implicity()
son.implicity()
output
PARENT implicity
PARENT implicity
class Parent(object):
def override(self):
print("PARENT override()")
class Child(Parent):
def override(self):
print("CHILD override()")
dad = Parent()
son = Child()
dad.override()
son.override()
output
PARENT override()
CHILD override()
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()
output
PARENT altered()
CHILD, BEFORE PARENT altered()
PARENT altered()
CHILD, AFTER PARENT altered()
class Parent(object):
def override(self):
print("PARENT override()")
def implicity(self):
print("PARENT implicity()")
def altered(self):
print("PARENT altered()")
class Child(Parent):
def override(self):
print("CHILD override()")
def altered(self):
print("CHILD, BEFORE PARENT altered()")
super(Child, self).altered()
print("CHILD, AFTER PARENT altered()")
dad = Parent()
son = Child()
dad.implicity()
son.implicity()
dad.override()
son.override()
dad.altered()
son.altered()
output
PARENT implicity()
PARENT implicity()
PARENT override()
CHILD override()
PARENT altered()
CHILD, BEFORE PARENT altered()
PARENT altered()
CHILD, AFTER PARENT altered()
2019-10-03
01:36:45
posted on 2019-10-02 20:20 petit_herisson 阅读(89) 评论(0) 收藏 举报
浙公网安备 33010602011771号