In this article, I will try to explain sealed class and sealed method in a very simple way.
C# Sealed Class
Sealed class is used to define the inheritance level of a class.
The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class.
Some points to remember:
- A class, which restricts inheritance for security reason is declared sealed class.
- Sealed class is the last class in the hierarchy.
- Sealed class can be a derived class but can't be a base class.
- A sealed class cannot also be an abstract class. Because abstract class has to provide functionality and here we are restricting it to inherit.
Practical demonstration of sealed class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sealed_class
{
class Program
{
public sealed class BaseClass
{
public void Display()
{
Console.WriteLine("This is a sealed class which can;t be further inherited");
}
}
public class Derived : BaseClass
{
// this Derived class can;t inherit BaseClass because it is sealed
}
static void Main(string[] args)
{
BaseClass obj = new BaseClass();
obj.Display();
Console.ReadLine();
}
}
}
C# Sealed Methods
Sealed method is used to define the overriding level of a virtual method.
Sealed keyword is always used with override keyword.
Practical demonstration of sealed method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sealed_method
{
class Program
{
public class BaseClass
{
public virtual void Display()
{
Console.WriteLine("Virtual method");
}
}
public class DerivedClass : BaseClass
{
// Now the display method have been sealed and can;t be overridden
public override sealed void Display()
{
Console.WriteLine("Sealed method");
}
}
//public class ThirdClass : DerivedClass
//{
// public override void Display()
// {
// Console.WriteLine("Here we try again to override display method which is not possible and will give error");
// }
//}
static void Main(string[] args)
{
DerivedClass ob1 = new DerivedClass();
ob1.Display();
Console.ReadLine();
}
}
}
Hope this article will give you better view of sealed class and sealed method. Waiting! for your valuable feedback.

Aditya ShrivastavaPosted Apr 14, 2018, 3:36 AM
Hi Puran, We make a configuration class which must not be inherited from any other class. I make this class as sealed. Now, I am making a class as sealed at first level. So, when you said that we can not make base class as sealed, you meant in reference to inheritance only. Am I right? Pratap asked somewhat same thing but if you can reply on this one, I will appreciate it. Thanks for your time.
Dennis ThomasPosted Jan 12, 2018, 6:57 AM
Good one Puran! It is simple and abstract.
Anant DhasPosted Apr 8, 2017, 12:55 AM
BUT WHY THERE SHOULD BE A NEED OF USE A CLASS WHICH CANT BE INHERITED?practically implementation?
prathapPosted Dec 7, 2016, 9:29 AM
Hi Puran, thanks for the article. You simplified the things. I am bit confused with the wording "Sealed class can be a derived class but can't be a base class." . If we are deriving some class means that should be the base class. I think it should be stated as "Sealed method can be derived, but cannot be overridden"
SubashPosted Sep 27, 2016, 2:49 AM
Thank you mehra for your simple explanation
Kumaresh RajalingamPosted Dec 31, 2015, 4:19 AM
Good one
Sujeet SumanPosted Oct 8, 2015, 6:00 AM
Nice Article..............
hassan wasefPosted Aug 18, 2013, 7:56 PM
the first Example of the Sealed class has a problem, as you defined a base class as sealed and that is not allowable.
Maharajan NatarajanPosted Mar 5, 2010, 9:34 AM
It is easy to understand. Good job. Keep it up.....
AnthonyBenedict PPosted Jun 19, 2009, 6:11 AM
What is the advantage to use sealed classes and in what kinda situation we should prefer to use sealed classes? Second question is, u wrote in this article "Sealed class can be a derived class but can't be a base class." What is the difference between a derived class and base class?
GopinatheditedPosted Jun 9, 2009, 1:31 AMEdited Jun 9, 2009, 1:32 AM
This Article..is Excellent...It is very simple & easy to understand...Thank u so much Mehra..for Providing such a good article.
Sumaira NoreenPosted Jun 4, 2009, 1:48 PM
A simple and very nice article, i have two queries Mehra What is the advantage to use sealed classes and in what kinda situation we should prefer to use sealed classes? Second question is, u wrote in this article "Sealed class can be a derived class but can't be a base class." What is the difference between a derived class and base class? Thanks,
Mahesh ChandPosted May 25, 2009, 8:17 PM
Keep up the good work Puran. Just post C# language related articles in C# Language section only. Going good.