Applying sealed to classes

The sealed keyword in C# when added to a class in C# prevents that class from being inherited.

public sealed class A
{
    public void ShowMessage()
    {
        Console.WriteLine("Class A");
    }
}

public class B: A
{

}

The compiler will display an error due to attempting to inherit class A, which is sealed, in class B.

Applying sealed to methods

When sealed is applied to methods, it prevents these methods from being overridden.

public class A
{
	public virtual void ShowMessage()
	{
		Console.WriteLine("Class A");
	}
}

public class B : A
{
	sealed public override void ShowMessage()
	{
		Console.WriteLine("Class B");
	}
}

public class C : B
{
	public override void ShowMessage()
	{
		Console.WriteLine("Class C");
	}
}

The compiler will throw an error in the example above: 'C.ShowMessage()': Cannot override inherited member 'B.ShowMessage()' because it is sealed.