Inheritance

The ability to be able to create your own classes that reuse, extend, and modify the behavior that the base class defines is called inheritance. Another important aspect to understand is that a derived class can only directly inherit a single base class.

Does this then mean that you can only inherit the behavior defined in a single base class? Well, yes and no. Inheritance is transitive in nature.

To explain this, imagine that you have three classes:

  • Person
  • Pedestrian
  • Driver

The Person class is the base class. Pedestrian inherits from the Person class and therefore Pedestrian inherits the members declared in the Person class. The Driver class inherits from the Pedestrian class and therefore Driver inherits the members declared ...

Get C# 7 and .NET Core 2.0 Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.