Bird
0
0

Which of the following is the correct syntax to declare an abstract base class in Python?

easy📝 Syntax Q3 of 15
Python - Polymorphism and Dynamic Behavior
Which of the following is the correct syntax to declare an abstract base class in Python?
Aclass MyClass(AbstractBaseClass):
Bclass MyClass(base):
Cclass MyClass(abstract):
Dclass MyClass(ABC):
Step-by-Step Solution
Solution:
  1. Step 1: Identify the base class for ABCs

    Python's abstract base classes inherit from ABC imported from abc module.
  2. Step 2: Check syntax correctness

    The correct syntax is 'class MyClass(ABC):' after importing ABC.
  3. Final Answer:

    class MyClass(ABC): -> Option D
  4. Quick Check:

    ABC inheritance syntax = class MyClass(ABC): [OK]
Quick Trick: Inherit from ABC to create abstract base class [OK]
Common Mistakes:
  • Using wrong base class names like AbstractBaseClass
  • Forgetting to import ABC from abc
  • Using lowercase 'abstract' or 'base' as base classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes