中国大学MOOC: 下面程序的运行结果是:class Student: def __init__(self,n=xxx,s=男): self.name=n self.sex=s def show(self): print(self.name,self.sex)s=Student(yyy)Student.show(s)
举一反三
- class Student: def __init__(self,n="xxx",s="男"): self.name=n self.sex=s def show(self): print(s.name,s.sex) s=Student("yyy") Student.show(s) 结果:
- class Person: def __init__(self,n="xxx"): self.name=n class Student(Person): def __init__(self,s="male"): self.sex=s def show(self): print(self.name,self.sex) s=Student("female") s.show() 结果:
- class Student: def __init__(self,n="xxx",s="男"): self.name=n self.sex=s def show(self): print(s.name,s.sex)s=Student("yyy")Student.show(s)结果: A: yyy 男 B: xxx 男 C: Student.show(s)错误 D: def __init__(self,n="xxx",s="男")错误
- class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") s.show() 结果
- class Person:def __init__(self,n="xxx"):self.name=nclass Student(Person):def __init__(self,s="male"):self.sex=sdef show(self):print(self.name,self.sex)s=Student("female")s.show()结果: A: xxx male B: xxx C: 结果错误 D: xxx female