What is a sealed class? can a method declared as sealed?

Posted by Rajendra.prasad under C# on 5/12/2011 | Points: 10 | Views : 5655 | Status : [Member] | Replies : 5
Hi,
What is a sealed class? can a method declared as sealed?

Regards,
Rajendra




Responses

Posted by: Vinith on: 5/12/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
Sealed class is a class which can't inherited. Sealed keyword is used to make class Sealed,once we define a class using Sealed that can't be inherited.

In C# Language a method can't be declared as sealed .

Thanks,

Vinith Anthony

Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Msahoo on: 5/12/2011 [Member] Starter | Points: 25

Up
0
Down
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

Posted by: Lakn2 on: 5/13/2011 [Member] Starter | Points: 25

Up
0
Down
Sealed Class means we can't inherit from that class means if we want to restirct access to a paricular class make that class as a sealed class.

Thanks&Regards
LakshmiNarayana Nalluri.

Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/13/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,
refer the below link....

http://msdn.microsoft.com/en-us/library/ms173150.aspx#Y704
Thanks,

Nitha Deepak

Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 5/19/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Refer this,

http://msdn.microsoft.com/en-us/library/88c54tsw.aspx#Y375

Regards,
Susan

Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response