Sunday, May 31, 2009

What is sealed class and sealed method?

In this article I will try to explain sealed class and sealed method in a very simple way.
Sealed Class

Sealed class is used to define the inheritance level of a class.
The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class.

Some points to remember:
1. A class, which restricts inheritance for security reason is declared, sealed class.
2. Sealed class is the last class in the hierarchy.
3. Sealed class can be a derived class but can't be a base class.
4. A sealed class cannot also be an abstract class. Because abstract class has to provide functionality and here we are restricting it to inherit.

Practical demonstration of sealed class
See full detail: http://www.c-sharpcorner.com/UploadFile/puranindia/sealedclass_sealedmethod05252009042850AM/sealedclass_sealedmethod.aspx

No comments: