Monday, February 1, 2010

Static Class and Member

Static class is a class which can be declared as Static.It contains only static member and private constructor.Private constructor prevents the class from being instantiated.So it doesn't allow to create instance of a static class using new keyword.
We can directly access methods from static class using class name.

The main features of a static class are:
* They only contain static members.
* They cannot be instantiated.
* They are sealed.
* They cannot contain Instance Constructors which means that it contains private constructor or static constructor.
Advantage :
  1. Normally the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.
  2. Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

0 comments:

Post a Comment