class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name)s=Student("yyy")s.show()结果
A: yyy
B: xxx
C: None
D: 错误
A: yyy
B: xxx
C: None
D: 错误
举一反三
- 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=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",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=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