Questions
Questions

Fal25_CS003C_74229 Ch. 9 Pre-Quiz (Remotely Proctored)

Single choice

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?

Options
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) : . . .
View Explanation

View Explanation

Verified Answer
Please login to view
Step-by-Step Analysis
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

Log in for full answers

We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

Similar Questions

More Practical Tools for Students Powered by AI Study Helper

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!