中国大学MOOC: 阅读以下代码,四个选项中说法正确的是(____)。class parent: def __init__(self,param): self.v1=paramclass child(parent): def __init__(self,param): parent.__init__(self,param) self.v2=paramodj=child(100)
举一反三
- class Student:def __init__(self,name,age):self.name=nameself.age=agedef fun1(self):print("hello")( )def fun2(self):print("yes")child=Child("Tom",20)child.fun1()
- 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() 结果:
- 以下有关类的声明,正确的是 A: class Student(object) def __init__(self, name, score): self.name = name self.score = score B: class Student(object) def __init__(self, name, score) self.name = name self.score = score C: class Student(object): def __init__(self, name, score): self.name = name self.score = score D: class Student(object): def __int__(self, name, score): self.name = name self.score = score
- class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") s.show() 结果
- 下列程序的输出结果是( )。class Fruit(): def __init__(self): print('Fruit') def grow(self): print('Fruit grow')class Vegetable(): def __init__(self): print('Vegetable') def grow(self): print('Vegetable grow') class Tomato(Fruit,Vegetable): passt = Tomato()t.grow()知识点:多继承 A: FruitFruit grow B: FruitVegetable grow C: VegetableFruit grow D: VegetableVegetable grow