Saturday, May 5, 2018

C# : What is sealed class in c#

Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, the class cannot be inherited. 

In C#, the sealed modifier is used to define a class as sealed. In Visual Basic .NET the Not Inheritable keyword serves the purpose of sealed. If a class is derived from a sealed class then the compiler throws an error. 

If you have ever noticed, structs are sealed. You cannot derive a class from a struct. 

The following class definition defines a sealed class in C#: 
  1. // Sealed class  
  2. sealed class SealedClass  
  3. {  
  4.   
  5. }  

No comments:

Post a Comment