PCAP Object-Oriented Programming Practice Question
Which TWO of the following are valid ways to define a class method in Python? (Select exactly two.)
⚠ Common exam trap
Python Institute often tests the distinction between the explicit `classmethod()` call and the decorator syntax, and the trap here is that candidates may think only the `@classmethod` decorator is valid, overlooking the manual `classmethod()` function call as an equally valid alternative.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
def my_method(cls): pass my_method = classmethod(my_method)
It manually applies the `classmethod()` built-in function to a regular function, converting it into a class method. This is a valid, though less common, way to define a class method, as the `classmethod` descriptor wraps the function so that the first argument passed is the class (`cls`), not an instance.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
def my_method(cls): pass my_method = classmethod(my_method)
Why this is correct
This is a valid, if less common, manual application of the classmethod() built-in. The module-level function is defined with a first parameter named cls, and then classmethod(my_method) wraps that function in a classmethod descriptor before assigning it back to the same name. From that point on, accessing the attribute on the class or on an instance binds the class object as the first argument, exactly as the @classmethod decorator would do at class creation time.
- ✗
class MyClass: def my_method(cls): pass
Why it's wrong here
Inside a class body, a bare def creates an instance method descriptor, not a class method; the name cls does not change that binding behavior. When the method is called on an instance, Python automatically passes the instance as the first argument, so cls receives the instance object, and when accessed through the class it remains an unbound function requiring an explicit class argument. Without the @classmethod decorator or a classmethod(my_method) assignment, the method lacks the descriptor logic needed to bind the class itself.
- ✗
def my_method(self): pass
Why it's wrong here
This code snippet is simply a plain function definition with a self parameter; it does not define a class and it does not create any binding behavior. If this function were later placed inside a class body unchanged, it would be an ordinary instance method, receiving an instance as its first argument. It cannot behave as a class method because nothing marks it with @classmethod or passes it through classmethod(), so the class object is never implicitly supplied.
- ✗
@staticmethod def my_method(cls): pass
Why it's wrong here
The @staticmethod decorator intentionally strips the descriptor binding behavior: the method becomes an ordinary function stored in the class namespace, so neither the class nor an instance is passed automatically. Even though the parameter is named cls, that name is only a convention and has no effect on how arguments are supplied; the caller must explicitly pass the class if it is needed. Therefore this defines a static method, not a class method, and any reference to cls will receive whatever explicit argument the caller provides, not the class.
- ✓
@classmethod def my_method(cls): pass
Why this is correct
This is the canonical class method definition: the @classmethod decorator wraps the function in a classmethod descriptor, and whenever the method is accessed—whether through the class or an instance—the descriptor inserts the class object as the first positional argument. The parameter is conventionally named cls to make that binding explicit and readable. This declarative form is exactly equivalent at runtime to the manual classmethod() assignment shown in the correct alternate answer.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.