Sealed classes are used to restrict the inheritance feature of OOPs. Once a class is defined as sealed class, that class cannot be inherited.
In C#, the sealed modifier is used to define a class as sealed. In Visual Basic .NET, NotInheritable keyword serves the purpose of sealed.
When an instance method declaration includes a sealed modifier, that method is said to be a sealed method. If an instance method declaration includes the
sealed modifier , it must also include the
override modifier . Use of the sealed modifier prevents a derived class from further overriding the method.
Ex :
class A
{
sealed override public void F() {
Console.WriteLine("A.F");
}
override public void G() {
Console.WriteLine("A.G");
}
}
class B: A
{
override public void G() {
Console.WriteLine("B.G");
}
}
here in B class you can not override A's F method.
Thank You.
Regards,
Manoranjan Sahoo
http://www.dotnetsquare.com
Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator