Private constructor and static constructor

Posted by Jobin under C# on 7/31/2012 | Points: 10 | Views : 1220 | Status : [Member] | Replies : 2
Difference between Private constructor and static constructor?




Responses

Posted by: Ogipansrk on: 8/2/2012 [Member] Starter | Points: 25

Up
0
Down

Private Constructor :
When a class has a private constructor , we cannot create an object for it.
You cannot inherit that class also.


Static Constructor : The code within the static constructor is executed only once.




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

Posted by: Ranjeet_8 on: 8/2/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
A private constructor is a special instance constructor.
It is commonly used in classes that contain static members only.
If a class has one or more private constructors and no public constructors,
then other classes (except nested classes) are not allowed to create instances of this class.

A static Variable is a Variable that is declared Static and initialized,
the Value cannot be changed it stays like that no matter what.
You can use Static Variables in Calculations where you need constants.


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

Login to post response