-
Hey friends, I am stuck here understanding static constructors. Have gone through many posts and online articles. But I am unclear yet. It says static constructor is called automatically before the first instance is created. But instance is created using default constructor, then how the static constructor is used in object creation? I know I am making a weird mistake but confused. Please help.0
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a
member of our community. Consider creating an
account or login.
Replies
-
Member • Jan 9, 2013
would you please specify which language you are talking about?
As per Java, if you declare a constructor as static it will not longer be "a" constructor.Are you sure? This action cannot be undone. -
Member • Jan 9, 2013
Working in C#
ianoopwould you please specify which language you are talking about?
As per Java, if you declare a constructor as static it will not longer be "a" constructor.Are you sure? This action cannot be undone. -
Member • Jan 10, 2013
😀 I am going to tell the basic concept of static constructor which will clear its usage :patil.ashu01Hey friends, I am stuck here understanding static constructors. Have gone through many posts and online articles. But I am unclear yet. It says static constructor is called automatically before the first instance is created. But instance is created using default constructor, then how the static constructor is used in object creation? I know I am making a weird mistake but confused. Please help.
Static constructor is used to initialize the static variables.
Now if we initialize the static variables using the normal (ie non static) constructor, its value will be re-setted every time a new object is created.
And regarding ur question, if we have not created static constructor, then only default constructor will be used. I hope ur doubt is cleared 👍.Are you sure? This action cannot be undone. -
Member • Jan 10, 2013
Thank You...rahul69😀 I am going to tell the basic concept of static constructor which will clear its usage :
Static constructor is used to initialize the static variables.
Now if we initialize the static variables using the normal (ie non static) constructor, its value will be re-setted every time a new object is created.
And regarding ur question, if we have not created static constructor, then only default constructor will be used. I hope ur doubt is cleared 👍.Are you sure? This action cannot be undone. -
Member • Jan 10, 2013
you're welcome...patil.ashu01Thank You...Are you sure? This action cannot be undone.