Repaso
Español

What happens if you try Shape() when Shape is an abstract base class with an @abstractmethod area()?

Options

  1. It works, and the area() method simply returns None
  2. TypeError: it is not possible to instantiate an abstract class (Correct option)
  3. It creates a default Circle object for you automatically
  4. 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.

Key terms

Practice this question in Repaso