Thursday, June 16, 2011

What is difference between Private and Sealed Classes



Sealed Class:

"Sealed" keyword provide us facility to prevent a class to be inherited by other classes, so "Sealed" classes cannot be inherited by any other class.

You can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.

"Sealed" class can have constructor, and they can only be used by its object (non-static methods).

Private Class:

Private class cannot be used directly under any namespace, means we can only create private class as a nested class, to make it available only to class to whom its nested.

the only/mostly use of Private class/structure is to create a user-defined type, which you wants to be accessible to that class only.

NOTE:Nested/inner class can be public also and that can be accessible to inherited class or by object where as private nested/inner class is only accessible to its outer class .


Compiled By: Rajesh Rolen

Share This!


2 comments:

Anonymous said...

Howdy! This is kind of off topic but I need some advice frlm
an established blog. Is it hard to set up your ownn blog?
I'm not very techincal but I can figure things out pretty fast.
I'm thinking about creating my own but I'm not sure where to start.
Do you have any tips or suggestions? Appreciate it

Anonymous said...

If you desire to increase your know-how only keep visiting thjis
web site and be updated with the newest news update poksted here.

Powered By Blogger · Designed By Seo Blogger Templates