Bird
Raised Fist0

How can you enforce that all subclasses of an abstract base class 'Processor' implement both 'process' and 'reset' methods, and also provide a concrete method 'status' that returns 'Ready'?

hard🚀 Application Q9 of Q15
Python - Polymorphism and Dynamic Behavior
How can you enforce that all subclasses of an abstract base class 'Processor' implement both 'process' and 'reset' methods, and also provide a concrete method 'status' that returns 'Ready'?
ADefine all three methods with @abstractmethod decorator
BUse @abstractmethod on 'process' and 'reset' in Processor; define 'status' normally
CMake 'process' and 'reset' normal methods; decorate 'status' with @abstractmethod
DDefine 'process' and 'reset' as static methods; 'status' as abstractmethod
Step-by-Step Solution
Solution:
  1. Step 1: Mark 'process' and 'reset' as abstract methods

    Use @abstractmethod decorator on these methods to require implementation in subclasses.
  2. Step 2: Define 'status' as a concrete method

    Implement 'status' normally in Processor to provide shared functionality.
  3. Final Answer:

    Use @abstractmethod on 'process' and 'reset' in Processor; define 'status' normally -> Option B
  4. Quick Check:

    Abstract required methods + concrete shared method = Use @abstractmethod on 'process' and 'reset' in Processor; define 'status' normally [OK]
Quick Trick: Abstract methods require @abstractmethod; concrete methods are normal [OK]
Common Mistakes:
MISTAKES
  • Marking concrete methods as abstract
  • Not using @abstractmethod for required methods
  • Making abstract methods static incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes