在上一填空题的基础上,我们定义Dog类的父类Animal。class Animal(object): def __init__(self, name): self.name = name def getInfo(self): print(This animals name:, self.name) def sound(self): print(The sound of this animal goes?)如果要继承该Animal类,前一填空题中的Dog类需要修改一行,需要修改第1 行,修改成___________________(注意书写完整),如果调用dog.sound () ,该方法是否可以运行?(如果可以,请填写输出;如果不可以,请填写字母F)____________。(两个答案之间用一个半角分号分隔)
举一反三
- 以下有关类的声明,正确的是 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, name):self.name = namedef out(self):print('name:', self.name)终端应如何输入(创建实例)______、(调用方法)______,使其可以输出“name:王芳”}
- 请执行以下代码,说明错误出现的行数。1. class Dog(object):2. def __init__(self,name):3. self.name = name4. @property5. def eat(self):6. print(" %s is eating" %self.name)7. 8. d = Dog("wangwang")9. d.eat()知识点:属性的定义和使用
- 以下代码中,实例方法定义正确的是() A: class Student: def setName(self,name): self.name=name B: class Student: def setName(name): self.name=name C: class Student: def setName(self): self.name=name D: class Student: def setName(name,self): self.name=name
- Python中类的定义正确的是 A: class Phone: name = "" call(self, name) print(name, "打电话") B: class Phone: name = "" call(self, name) print(name, "打电话") C: class Phone: name = "" def call(self, name): print(name, "打电话") D: class Phone name = "" def call(self, name): print(name, "打电话")