【发布时间】:2013-03-19 04:58:47
【问题描述】:
问题:
- python 是否以这种方式加载方法 - 谁最后谁赢?即使您有两个方法共享确切的名称,即使使用不同的参数(不同的签名),最后一个方法也会覆盖前面的所有方法而不会出现运行时错误?
- 如果python没有重载,那么python推荐的JAVA重载方式是什么?
下面的例子:
class Base(object):
def __init__(self):
print "Base created without args"
def __init__(self, a):
print "Base created " + a + "\n"
print Base("test") 给我:
Base created test
<__main__.Base object at 0x1090fff10>
虽然print Base() 给了我:
Traceback (most recent call last):
File "${path to super file}/super.py", line 27, in <module>
print Base()
TypeError: __init__() takes exactly 2 arguments (1 given)
【问题讨论】:
标签: python constructor