How to prevent a class from being inherited in C#.NET?
- The sealed modifier is used to prevent derivation from a class.
- An error occurs if a sealed class is specified as the base class of another class.
- A sealed class cannot be an abstract class.
- Sealed method enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Example:class A
{
protected virtual void show()
{
//Statements
}
}
class B : A
{
sealed protected override void shoe()
{
//Statements
}
}