题目
题目

Fal25_CS003C_74229 Ch. 9 Pre-Quiz (Remotely Proctored)

单项选择题

Consider a class that represents a hardware device. The device can be in one of two states: Plugged in, or unplugged. Which of the following class definitions is best for this situation?

选项
A.class Device : def __init__(self) : self.PLUGGED_IN = 0 self.UNPLUGGED = 1 . . .
B.class Device : def __init__(self) : PLUGGED_IN = 0 UNPLUGGED = 1 . . .
C.PLUGGED_IN = 0 UNPLUGGED = 1 class Device : def __init__(self) : . . .
D.class Device : PLUGGED_IN = 0 UNPLUGGED = 1 def __init__(self) : . . .
查看解析

查看解析

标准答案
Please login to view
思路分析
The problem presents a design choice for modeling a hardware device that can be either plugged in or unplugged, and asks which class definition is best for this situation. Option A: class Device : def __init__(self) : self.PLUGGED_IN = 0 self.UNPLUGGED = 1 . . . In this version, the constants are defined as instance attributes inside __init__. This means every Device object would get its own copies of PLUGGED_IN and UNPLUGGED, which is unnecessary and wastefu......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!