Decorators Questions and Answers
Practice ModeShowing 10 of 25 questions
Q21
Which decorator is used to mark abstract methods?
Answer: Option B
Explanation: @abstractmethod from abc module is used to define abstract methods in abstract base classes.
Q22
Can decorators modify function return values?
Answer: Option B
Explanation: Yes, decorators can modify both function arguments and return values.
Q23
What is the main advantage of using decorators?
Answer: Option B
Explanation: Decorators promote code reuse and separation of concerns by modularizing cross-cutting functionality.
Q24
Which decorator would you use to time function execution?
Answer: Option D
Explanation: A custom timing decorator can be created using time module to measure function execution time.
Q25
Can decorators be chained with inheritance?
Answer: Option B
Explanation: Yes, decorators work with inheritance - decorated methods in parent classes affect child classes.