nerdexam
Python_Institute

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…

Advanced OOP

Question

Analyze the following snippet and decide whether the code is correct and/or which method should be distinguished as a class method.

Exhibit

PCPP-32-101 question #7 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)
  • A
    6% (2)
  • B
    15% (5)
  • C
    70% (23)
  • D
    9% (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

#@classmethod#class methods#class variables#decorators

Community Discussion

No community discussion yet for this question.

Full PCPP-32-101 Practice