下列程序的输出结果是( )。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
A: FruitFruit grow
B: FruitVegetable grow
C: VegetableFruit grow
D: VegetableVegetable grow
举一反三
- 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,name,age):self.name=nameself.age=agedef fun1(self):print("hello")( )def fun2(self):print("yes")child=Child("Tom",20)child.fun1()
- class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") 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) 结果:
- 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: 错误