sealed class contain a concrete methods.but it does not participate in inheritance why?

Posted by Harieswer under C# on 8/12/2015 | Points: 10 | Views : 292 | Status : [Member] | Replies : 2
sealed class contain a concrete methods.but it does not participate in inheritance why?,
if we use sealed class in inheritance ,its stop the inheritance why? and there is any specific reason tell me sir




Responses

Posted by: Shreedar on: 8/15/2015 [Member] Starter | Points: 25

Up
1
Down
Hi Harieswer.

If we want to avoid a class i.e., parent class from inheriting, then we declare that class as sealed class.

It is recommended to declare a class as sealed class, if we are not having implementation of that class at any other place.

Where as by declaring the method as sealed and class as public we can stop method from overriding but class can be inherited.

Sealed keyword has a code predefined which will not allow inheriting.

Regards

Sridhar Thota.

Regards

Sridhar Thota.
www.dotnet-sridhar.blogspot.com

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

Posted by: Rajnilari2015 on: 9/28/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
1
Down
If a class is Sealed then .NET doesn’t need to consult the virtual-function-call table to find the actual type, since it knows that no derived type can exist. Therefore, it could emit a ‘call’ instead of ‘callvirt’ or at least optimise the machine code, thus producing a performance benefit.

--
Thanks & Regards,
RNA Team

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

Login to post response