Background
In this article, we will learn about one of the most reusable object-oriented features of C#, Sealed classes. We will learn about Sealed classes from the basics because I have written this article focusing on the students and the beginners. Before proceeding further, please refer to my previous articles for a better understanding.
- Programming Methodologies
- Types of Classes in C#
- Polymorphism in C#
- Types of Inheritance in C#
- Method Overloading and Method overriding C#
So, let us start from the basics of Sealed classes.
What a Sealed Class is
It is a type of class that cannot be inherited.
The following are some key points:
- A Sealed class is created by using the sealed keyword
- The Access modifiers are not applied upon the sealed class
- To access the members of the sealed we need to create the object of that class
- To restrict the class from being inherited, the sealed keyword is used
Example
- public sealed class CustoMerDetails
- {
- public string AccountIno()
- {
- return "Vithal Wadje";
- }
- }
In the preceding example, the class is declared using the sealed keyword so that this class and the class member cannot be inherited, in other words, we cannot derive from the sealed class.
These types of classes are very Important when we want to restrict it to Inherit the class that provides the highest level of the security to the code, let us see the example of the sealed class, to demonstrate the sealed class, let us create a simple console application as:
- Open Visual Studio from Start - - All programs -- Microsoft Visual Studio
- Then, go to "File" -> "New" -> "Project..." then select the Visual C# -> Windows -> Console application
- After that, specify the name such as the SealedClass or whatever name you wish and the location of the project and click on the OK button. The new project is created.
Now, open the class file and create the following simple program as given below:


swapnali morePosted Jun 16, 2020, 9:57 AM
The Access modifiers are not applied upon the sealed class ..not clear for this statement ...can you please elaborate
swapnali morePosted Jun 16, 2020, 9:56 AM
Me too confuse for this sentence --The Access modifiers are not applied upon the sealed class
Ajeet MalviyaPosted Aug 8, 2019, 3:06 AM
"Access modifiers are not applied upon the sealed class" Whats this ? But you have applied access modifier in the sealed class public sealed class CustoMerDetails {}. I think thats not the correct statement.
Amit KaushalPosted Jul 18, 2017, 11:44 AM
I think its nothing like we can not specify access modifier before sealed class. Comment please.
manikant kumarPosted Jun 11, 2014, 2:42 AM
The Access modifiers are not applied upon the sealed class ...what is meant by this sentence???
Vithal WadjePosted May 29, 2014, 2:53 PM
thanks Dhananjay sir,your comment motivates me lot
Khan Abrar AhmedPosted May 29, 2014, 9:37 AM
Nice one sir
Former memberPosted May 29, 2014, 7:51 AM
Nice article !