#_*_encoding:utf-8_*_
class people:
#定义基本属性
name = ''
age = 0
#定义私有属性,私有属性在类的外部无法直接访问
__weight = 0
#定义构造方法
def __init__(self,a,w):#调用时需传入self相当于this
self.name = 'MHC'
self.age = a
self.weight = w
def speak(self):
print "%s is speaking: I am %d years old."%(self.name,self.age)
p = people(10,30)
p.speak()
class student(people):
grade = 0
def __init__(self,a,w,g):
#调用父类的构造函数
people.__init__(self,a,w)
self.grade = g
#覆写父类speak方法
def speak(self):
print "%s is speaking: I'am %d years,and I'm in grade %s "%(self.nameself.age,self.grade)
s = student(100,60,3,100)
s.speak()
你这什么都没有解答什么啊,至少代码贴一下吧
google的大神来了,都无法为你解答,