Sealed Class


A sealed class can not be inherited.

  • It cannot be used as a base class.
  • It prevents derivation.
  • It is created by using the sealed keyword.
  • To access the sealed members, the sealed class must be instantiated.
Example
public sealed class MySealedClass
{
   
}
Note:

Using the keyword sealed, we can stop the derived class from overriding a virtual class method.

Example
public class MyDerivedClass : MyBaseClass
{
   public sealed override void MyMethod() // Classes that inherit from MyDerivedClass can't override MyMethod
   { 
   }
}

Back to Notes