Inheritance

Inheritance is one of the main principles of any object-oriented programming. With inheritance, we can define attributes and functions that can be reused in child classes. In short, it helps us to reuse code written in the application across multiple modules. Let's go through an example to understand how inheritance helps us.

Let's consider two cars, CarA and CarB. From a very high-level perspective, we can think that both these classes will have similar features such as:

  • A brake function
  • An accelerator function
  • A car type; that is, diesel/petrol and so on
  • Color
  • Gear type

If we need to implement this in a C# application, one way would be to define them as two separate classes: CarA and CarB . However, the main concern with this ...

Get Programming in C#: Exam 70-483 (MCSD) Guide 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.