PCPP-32-101 · Question #55
Analyze the following snippet. Which method should be distinguished as a static method?
The correct answer is A. The isElementCorrect() method should be static. The isElementCorrect() method does not use self or any instance attributes and only processes its input parameter, so it should be defined as a static method. The isSolved() method relies on the instance attribute self.progress and must remain an instance method.
Question
Analyze the following snippet. Which method should be distinguished as a static method?
Exhibit
Options
- AThe isElementCorrect() method should be static.
- BBoth methods should be static.
- CThe isSolved() method should be static.
- DNone of the methods should be static.
How the community answered
(31 responses)- A55% (17)
- B13% (4)
- C6% (2)
- D26% (8)
Explanation
The isElementCorrect() method does not use self or any instance attributes and only processes its input parameter, so it should be defined as a static method. The isSolved() method relies on the instance attribute self.progress and must remain an instance method.
Topics
Community Discussion
No community discussion yet for this question.
