$ cat inheritance_overided_method.py
#!/usr/bin/python
# -*- encoding: utf-8 -*-
"""inheritance_overided_method:
parent -- func() --> func1()
|
(inherit)
|
child -- func() --> Parent.func()
Then, which func1() will been called,
parent.func1() or child func1 or both?"""
class parent:
def func(self): self.func1()
def func1(self): print "parent.func1"
class child(parent):
# def func(self): parent.func()
def func(self): parent.func(self)
def func1(self): print "child.func1"
obj = child()
obj.func()
可以看到,
parent.func1() 完全没有执行!
没有评论:
发表评论