in Education by

What are sealed classes in C#?

1 Answer

0 votes
by
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 the sealed class. 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. }    

Related questions

0 votes
    What are partial classes?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What are extension methods in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What are accessors in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What is Boxing and Unboxing in C#?...
asked Jul 9, 2021 in General by JackTerrance
0 votes
    What is a Hashtable in C#?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What is Serialization in C#?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    What is the difference between late binding and early binding in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What is IEnumerable in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What is the difference between boxing and unboxing in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What is the difference between String and StringBuilder in C#?...
asked Mar 31, 2021 in Education by JackTerrance
0 votes
    What are the Templates in WPF ?...
asked Apr 9, 2021 in Education by JackTerrance
...