Google News
logo
C# - Interview Questions
What are sealed classes in C#?
Sealed classes are used to restrict the users from inheriting the class. A class can be sealed by using the sealed keyword. The keyword tells the compiler that the class is sealed, and therefore, cannot be extended. No class can be derived from a sealed class.
 
The following is the syntax of a sealed class :
sealed class class_name
{
    // data members
    // methods
    .
    .
    .

}
A method can also be sealed, and in that case, the method cannot be overridden. However, a method can be sealed in the classes in which they have been inherited. If you want to declare a method as sealed, then it has to be declared as virtual in its base class.
Advertisement