What are sealed classes in C#?
1346
18-Mar-2018
Anonymous User
18-Mar-2018We create sealed class when we want to restrict or prevent the class to be inherited. Sealed modifier is used to prevent derivation from a class. If we try to specify a sealed class as base class then a compile-time error occurs.
If we try to inherit sealed class then following error well be occure
class MyDerivedC: SealedClass {} // Error
The result is an error message:
'MyDerivedC' cannot inherit from sealed class 'SealedClass'.