Bird
0
0

What happens if you try to instantiate an abstract base class directly in Python?

easy📝 Conceptual Q1 of 15
Python - Polymorphism and Dynamic Behavior
What happens if you try to instantiate an abstract base class directly in Python?
AIt creates an object but abstract methods return None
BIt creates an object normally without errors
CIt raises a SyntaxError
DIt raises a TypeError because abstract methods are not implemented
Step-by-Step Solution
Solution:
  1. Step 1: Understand abstract base class instantiation rules

    Abstract base classes (ABCs) cannot be instantiated if they have abstract methods not implemented.
  2. Step 2: Check what happens when instantiating an ABC

    Python raises a TypeError if you try to create an instance of an ABC with unimplemented abstract methods.
  3. Final Answer:

    It raises a TypeError because abstract methods are not implemented -> Option D
  4. Quick Check:

    Instantiating ABC = TypeError [OK]
Quick Trick: Cannot create ABC instance if abstract methods exist [OK]
Common Mistakes:
  • Thinking ABCs can be instantiated like normal classes
  • Confusing SyntaxError with TypeError
  • Assuming abstract methods return None by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes