Bird
0
0

Which of the following is the correct way to declare an abstract method in a Python abstract base class?

easy📝 Syntax Q12 of 15
Python - Polymorphism and Dynamic Behavior
Which of the following is the correct way to declare an abstract method in a Python abstract base class?
A@abstractmethod\ndef method(self): pass
B@abstract\ndef method(self): pass
Cdef abstract method(self): pass
Ddef method(self): pass
Step-by-Step Solution
Solution:
  1. Step 1: Recall abstract method syntax

    In Python, abstract methods are decorated with @abstractmethod from the abc module.
  2. Step 2: Match options with correct syntax

    Only '@abstractmethod\ndef method(self): pass' uses @abstractmethod decorator correctly. 'def method(self): pass' misses the decorator, '@abstract\ndef method(self): pass' uses a wrong decorator name, and 'def abstract method(self): pass' uses invalid syntax.
  3. Final Answer:

    @abstractmethod\ndef method(self): pass -> Option A
  4. Quick Check:

    Use @abstractmethod decorator [OK]
Quick Trick: Use @abstractmethod decorator for abstract methods [OK]
Common Mistakes:
  • Omitting the @abstractmethod decorator
  • Using wrong decorator names
  • Writing invalid method definitions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes