【发布时间】:2012-09-15 11:23:49
【问题描述】:
如果我有课:
class Person(object):
'''A class with several methods that revolve around a person's Name and Age.'''
def __init__(self, name = 'Jane Doe', year = 2012):
'''The default constructor for the Person class.'''
self.n = name
self.y = year
然后是这个子类:
class Instructor(Person):
'''A subclass of the Person class, overloads the constructor with a new parameter.'''
def __init__(self, name, year, degree):
Person.__init__(self, name, year)
对于如何让子类调用并使用name 和year 的父类构造函数,同时在子类中添加新参数degree,我有点迷茫。
【问题讨论】:
-
你有什么问题?
-
你做的应该没问题...
-
哦,好吧,我不确定,也想不出测试它的方法……我发现我一直都是正确的……我很抱歉。
标签: python inheritance