Abstract Classes

An abstract class is a blueprint that cannot be instantiated directly.

It exists to define a shared structure and to enforce certain methods that child classes must implement.

An abstract method is declared but not implemented in the abstract class. It defines a contract. Any child class extending the abstract class must provide its own implementation of that method.

Abstract classes are used when multiple child classes share common behavior but must implement their own specific variation of some functionality.

Key rules:

  • You cannot create an object from an abstract class.
  • If a class extends an abstract class, it must implement all abstract methods.
  • The child method must use the same name and required arguments.
  • The child method cannot be more restrictive in visibility.

Conceptually, abstract classes define “what must exist”, while child classes define “how it works”.