inheritance

Declaring one class or type as a specialised version of another, so it receives the parent's members and can be used wherever the parent is expected.

In more detail

It lets a new type reuse and override behaviour from an existing one. Deep hierarchies are hard to change, so many designs prefer composition and small interfaces.

Examples

C#: members marked virtual or abstract can be replaced with override; the course seals classes by default.
Java: a class extends one parent class and may implement many interfaces; sealed types restrict who may extend them; records cannot extend a class.
static class StorageFailure extends RuntimeException { }
class Puppy(Dog): makes Puppy a subclass of Dog; prefer composition for has-a relationships.
class Puppy(Dog):
    pass

Related terms

Taught in

References

Certification courses