Search⌘ K
AI Features

Inheriting from Abstract Class

Explore how to inherit from abstract classes in C# and understand the role of abstract classes in providing partial implementations. Learn how to use the sealed keyword to prevent further inheritance or overriding, and discover the differences between hiding and overriding methods through polymorphism. This lesson helps you grasp essential object-oriented programming concepts to build robust and maintainable C# applications.

We learned about interfaces that can define a set of members that a type must have to meet a basic level of functionality. These are very useful, but their main limitation is that until C# 8, they could not provide any implementation of their own. This is a particular problem if we still need to create class libraries that will work with the .NET Framework and other platforms that do not support .NET Standard 2.1.

Abstract classes

In those earlier platforms, we could use abstract classes as a sort of halfway house between a pure interface and a fully implemented class. When a class is marked as abstract, this means that it cannot be instantiated because we are indicating that the class is not complete. It needs more implementation before it can be instantiated. For example, the System.IO.Stream class is abstract because it implements common ...