#Q002. 类与对象
类与对象
🧠 Python 类与对象综合练习题
一、单项选择题(每题 5 分)
1. 定义类时使用的关键字是:
{{ select(1) }}
- object
- class
- def
- init
2. 构造函数的正确定义方式是:
{{ select(2) }}
def init(self):def __init__():def __init__(self):def init():
3. 在类中定义属性时,必须加上的前缀是:
{{ select(3) }}
this.self.class.- 无需前缀
4. 创建对象时会自动调用的函数是:
{{ select(4) }}
__init__mainselfcreate
5. 若要创建 Hero 类的实例,应使用:
{{ select(5) }}
Hero.create()Hero.new()Hero()Hero.__init__()
6. 方法中必须包含的第一个参数是:
{{ select(6) }}
thisselfobjthat
7. 下列哪种写法可以让子类继承父类?
{{ select(7) }}
class Child(Parent):class Parent(Child):class Parent = Child:class Child - Parent:
8. 在子类中调用父类构造函数的关键字是:
{{ select(8) }}
selfthissuper()parent()
9. 调用方法的正确方式是:
{{ select(9) }}
Hero.attack()attack.Hero()hero.attack()self.attack()
10. 类名的书写规范一般是:
{{ select(10) }}
- 全小写
- 下划线连接
- 首字母大写(大驼峰)
- 全大写
二、多项选择题(每题 5 分)
11. 关于 self 的描述正确的是:
{{ multiselect(11) }}
- 表示当前对象
- 可以省略不写
- 用于访问对象属性
- 用于区分类变量和实例变量
12. 关于继承(Inheritance),以下说法正确的是:
{{ multiselect(12) }}
- 子类可以访问父类的方法
- 子类不能调用父类构造函数
- 子类可以重写父类的方法
- 继承可以提高代码复用性
13. 关于方法重写(Override),下列正确的是:
{{ multiselect(13) }}
- 子类方法名必须与父类相同
- 子类可改变父类方法的功能
- 父类方法会被覆盖
- 父类方法会自动执行
14. 以下哪些语句是正确的对象操作?
{{ multiselect(14) }}
xiaoli = Player("小李", 999, 100)xiaomin.attack()print(xiaomin.hp)Hero("小明", 100, 50).upgrade()
三、填空题(每题 5 分)
15. 使用 {{ input(15) }}关键字定义一个类。
16. 构造函数的函数名必须是 {{ input(16) }}。
17. 在类中访问对象的属性和方法时,需要通过 {{ input(17) }} 关键字。
18. 在子类中调用父类构造函数时应使用 {{ input(18) }}关键字。
19. 类是创建 {{ input(19) }} 的模板。
20. 在定义方法时,第一个参数通常命名为 {{ input(20) }}.
四、判断题(每题 5 分,A: 对,B: 错)
21. init 方法在对象实例化时会自动执行。
{{ select(21) }}
- A: 对
- B: 错
22. 子类创建对象时,不会自动调用父类的构造函数。
{{ select(22) }}
- A: 对
- B: 错
23. 类中定义的方法不能访问属性。
{{ select(23) }}
- A: 对
- B: 错
24. 使用 super() 可以调用父类的属性和方法。
{{ select(24) }}
- A: 对
- B: 错
25. 对象是类的实例。
{{ select(25) }}
- A: 对
- B: 错