📝 What is sealed Class in C#?
When applied to a class, the sealed modifier prevents other classes from inheriting from it. In the following example, class B inherits from class A, but no class can inherit from class B.
You can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Summary:
🔸 Once a class is defined as a sealed class, the class cannot be inherited.
🔸 Structs are also sealed.
When applied to a class, the sealed modifier prevents other classes from inheriting from it. In the following example, class B inherits from class A, but no class can inherit from class B.
You can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Summary:
🔸 Once a class is defined as a sealed class, the class cannot be inherited.
🔸 Structs are also sealed.