0
私はStudentBodyという親クラスとMathStudentBodyという子クラスを持っています。私の質問は、クラス内の生徒の総数を見つけるために、どのように子クラスを説明することができるのですか?私は作成されたオブジェクトの総数を調べなければならないと思いますか?あなたはこのような何かを意味生徒の総数を確認
class StudentBody:
count = 0
def __init__(self, name,gender,year,gpa):
self.name = name
self.gender = gender
self.year = year
self.gpa = gpa
self.count+= 1
def IsFreshman(self):
print "I am the StudentBody method"
if self.year == 1:
return True
else :
return False
def countTotal(self):
return self.count
class MathStudentBody(StudentBody):
def __init__(self,name,gender,year,gpa,mathSATScore):
#super(MathStudentBody,self).__init__(name,gender,year,gpa)
StudentBody.__init__(self,name,gender,year,gpa)
self.MathSATScore = mathSATScore
def IsFreshman(self):
print "I am the MathStudentBody method"
def CombinedSATandGPA(self):
return self.gpa*100 + self.MathSATScore
def NumberOfStudents(self):
return
あなたは 'self.count + = 1 'を呼び出し、これは失敗しないのですか? –
@WillemVanOnsem:いいえ、それは 'StudentBody.count'にアクセスするだけです。 –