在下面的代碼我想實現繼承和多態特性,我的問題是obj1.hello3("1param","2param") obj1.hello3("11param")
是這些語句不正確會是什麼做的正確的方式這傳承與多態特性
#!/usr/bin/python
class test1:
c,d = ""
def __init__(self,n):
self.name = n
print self.name+"==In a"
def hello1(self):
print "Hello1"
def hello3(self,a,b):
#print "Hello3 2 param"+str(a)+str(b)
#print "ab"+str(self.a)+str(self.b)+"Hello1"
print "Hello3 2 param"
def hello3(self,a):
#print "a"+str(self.a)+"Hello1"
print "Hello3 1 param"+str(a)
class test2(test1):
def __init__(self,b):
test1.__init__(self, "new")
self.newname = b
print self.newname+"==In b"
def hello2(self):
print "Hello2"
obj= test1("aaaa")
obj1=test2("bbbb")
obj1.hello1()
obj1.hello2()
obj1.hello3("1param","2param")
obj1.hello3("11param")
python中不支持方法重載嗎? – Rajeev