|
class Parent(object):
def __init__(self):
self.parent = "Good"
print ('Parent')
def identity(self, message):
print ("%s I'm parent" % message)
class Child(Parent):
def __init__(self):
super(Child, self).__init__() #首先找到Child的父类(Parent),然后把类Child的对象转换为类Parent的对象,调用父类的构造函数__init__()
print ('Child')
print("******"*4)
def identity(self, message):
super(Child, self).identity(message) #首先找到Child的父类(Parent),然后把类Child的对象转换为类Parent的对象,调用父类的identity(message)函数
print ("I'm child")
print("******" * 4)
print (self.parent)
if __name__ == '__main__':
Test = Child()
Test.identity('hello China') |
|
|