What are sealed modifiers in C#?

CsharpProgrammingServer Side Programming

When you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.

Let us see an example −

The following example won’t allow you to override the method display() because it has a sealed modifier for the ClassTwo derived class −

ClassOne is our base class, whereas ClassTwo and ClassThree are derived classes −


class ClassOne {
   public virtual void display() {

class ClassTwo : ClassOne {
   public sealed override void display() {

class ClassThree : ClassTwo {
   public override void display() {
      Console.WriteLine("ClassThree: Another Derived Class");

Above, under ClassThree derived class we have tried to override the sealed method. This will show an error since it is not allowed when you use the sealed method.

Updated on 21-Jun-2020 11:57:56