Abstract Classes

Learn about classes that can’t be instantiated.

We'll cover the following

Abstract classes

C# includes abstract classes in addition to the regular classes. An abstract class is a class that can’t be instantiated. It can hold some common functionality for its child classes.

Abstract classes are useful when we don’t want to use their instances in our program but need to store common functionality to avoid code repetition.

Let’s consider an example using the Vehicle, Car, and Motorcycle classes we’ve looked at before. The Vehicle class holds members common to all vehicles, but a vehicle is an abstract concept. Cars and motorcycles, though, are definite things.

Therefore, we can mark our Vehicle class as abstract because we won’t use its instances.

We use the abstract keyword to do this:

Get hands-on with 1400+ tech skills courses.