interviews.dotnetthread.com

↑ Grab this Headline Animator

Thursday, June 26, 2008

What are abstract and sealed clases?

Abstract-Abstract classes are usually created to serve as base classes.A class defined using the abstract keyword cannot be instantiated
For example, your program may need three classes that have many members in common, but differ in a few crucial details. A good programming strategy would be to create an abstract class that contains all the common elements, then create the three individual classes that each inherits from the abstract class. Abstract classes can also be used to provide functionality without data storage, such as the Math class in the .Net Framework.

Sealed-A sealed class is sort of the opposite of abstract.It can be instantiated but cannot serve as a base class.
The primary reason to seal a class is to prevent your users from fiddling around with it and breaking it (and of course blaming you, usually!). It's also the case that sealing a class permits certain compiler optimizations that are not possible with non-sealed classes. Obviously, a class cannot be both sealed and abstract.

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles