What happens if you try Shape() when Shape is an abstract base class with an @abstractmethod area()?
Options
- It works, and the
area()method simply returns None - TypeError: it is not possible to instantiate an abstract class (Correct option)
- It creates a default Circle object for you automatically
- SyntaxError, which is raised when the file is loaded
Answer
TypeError: can't instantiate abstract class
Why
An abstract class is a template that is not meant to be used directly. It declares methods that every subclass MUST implement.
Python refuses to create an object from it. A subclass like Circle that implements area() can be created normally.
This guarantees that every shape really has an area() method.
Remember
Abstract classes define the contract; only complete subclasses can be created.