Sealed class is used to prevent the class from being inherited from other classes. So “sealed” modifier also can be used with methods to avoid the methods to override in the child classes.
Example :
Example :
class X {} sealed class Y : X {} Sealed methods – class A { protected virtual void First() { } protected virtual void Second() { } } class B : A { sealed protected override void First() {} protected override void Second() { } }
If any class inherits from class “B” then method – “First” will not be overridable as this method is sealed in class B.
No comments:
Post a Comment