C# Sealed Class

Sealed classes that cannot be inherited by any other class. Sealed class is used restrict the inheritance. Using the sealed keyword you can create sealed class, and also you can used sealed access modifier to create sealed method which can not be inherited in any other class.

Example of Sealed Class

sealed class Sample
{
    public sealed void Display(string str)
    {
        Console.WriteLine(str);
    }
}

public class Demo : Sample // it will given an error
{
}

Points to Remember

  • Sealed class cannot be inherited in any other class
  • Sealed method cannot be inherited in derived class
  • Sealed class you cannot define as static