Sealed Class
Sealed classed can not be inherited, if you try to inherit from a sealed class then you will get a compile time error. Sealed classes are declared using a sealed keyword as shown below.
public sealed class sealedClassDemo
{
}
As shown in the below example we are trying to inherit from a sealed class and on the same time we can see a error message saying that we can not inherit from a sealed class.
The most common use of sealed class is to stop the inheritance but you can still extend the sealed class using extension methods. So as shown in the below example we can extend the sealed class by having a extension method, to know more about extension methods please read my blog on extension methods in C#.
So today we have discussed regarding sealed class in C# and there importance, how sealed keyword can be used.
Thank You for taking your time and reading my post on sealed class, please read my other posts related to C#, jQuery and .NET.
If you have any other questions related to .NET or C# then please write them in the comments section or write a mail on prson94@gmail.com and I will try to get back to you as soon as possible.
0 comments:
Post a Comment