Sitemap
.Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Member-only story

C# CONCEPTS

Sealed v/s Abstract Classes

The article demonstrates the use of abstract and sealed class

2 min readMay 11, 2021

--

Photo by Sabrina Gelbart from Pexels

Learning Objectives

  • What is a Sealed class
  • What is an Abstract class

Prerequisites

Require a basic understanding of OOPS concepts.

Getting Started

Sealed Class

The sealed keyword permits restriction of the inheritance of a class or its members.

To mark a class as sealed, put the keyword sealed before the class definition. For example:

public sealed class D {
// Class members here.
}

Sealed classes prevent derivation as they cannot act as a base class.

Common Usage of Sealed Class

Any method, indexer, property, or event on a derived class overriding a virtual member of the base class can declare that member sealed. It negates the virtual aspect of the member for any further inheritance. Simply putting a sealed keyword before the override keyword in the class member declaration. For example:

public class D : C {     
public sealed override void Do() { }
}

--

--

.Net Programming
.Net Programming

Published in .Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Sukhpinder Singh | C# .Net
Sukhpinder Singh | C# .Net

Written by Sukhpinder Singh | C# .Net

C# .Net developer 👨‍💻 who's 100% convinced my bugs are funnier than yours. 🐛💥 #BugLife Pubs: https://medium.com/c-sharp-programming

No responses yet