Main advantage of Private class and Sealed Classes?

Posted by Naga116 under C# on 8/3/2011 | Points: 10 | Views : 11842 | Status : [Member] | Replies : 2
Hi,

Private and Sealed classes having same significance or any difference is there ?

Can you please explain?

Nagaraju


Responses

Posted by: Hmanjarawala on: 8/3/2011 [Member] Bronze | Points: 25

Up
0
Down
Sealed Class:

A class which restricts inheritance for security region is called Sealed class.
Sealed class is the last class in hierarchy.
Sealed class can be a derived class but can't be a base class.
To access the members of sealed class we should create the instance object.

Advantages of sealed class is it restrict the third party vendor for developing new software by inheriting from our logic.

Private Class:

Classes and structs that are not nested within other

classes or structs can be either public or internal. A type

declared as public is accessible by any other type. A type

declared as internal is only accessible by types within the

same assembly. Classes and structs are declared as internal

by default unless the keyword public is added to the class

definition. And yes, a class cannot be private unless of

course if it a nested class.

Restricts the access to the class itself. Only methods that are part of the same class can access private members.




Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

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

Posted by: Akiii on: 8/3/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

If you have a class library , not all classes are required to be exposed to the user. You can mark those as private.
On the other way, sealed classes are used when you don't want your class to be inherited further.

Thanks and Regards
Akiii

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

Login to post response