PCPP-32-101 · Question #7
Analyze the following snippet and decide whether the code is correct and/or which method should be distinguished as a class method.
The correct answer is C. The code is erroneous. The isElementCorrect method is decorated as a @staticmethod but incorrectly tries to call self.isSolved(), which is an instance method. Static methods do not have access to self because they do not require an instance of the class to be called. They work at the class level, not…
Question
Analyze the following snippet and decide whether the code is correct and/or which method should be distinguished as a class method.
Exhibit
Options
- AThere is only one initializer, so there is no need for a class method
- BThe getNumberOfCrosswords() method Should be decorated with @classmethod
- CThe code is erroneous
- DThe getNumberOfCrosswords() and isSolved methods should be decorated with @classmethod
How the community answered
(33 responses)- A6% (2)
- B15% (5)
- C70% (23)
- D9% (3)
Explanation
The isElementCorrect method is decorated as a @staticmethod but incorrectly tries to call self.isSolved(), which is an instance method. Static methods do not have access to self because they do not require an instance of the class to be called. They work at the class level, not the
Topics
Community Discussion
No community discussion yet for this question.
