How the static constructor is used in object creation?

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.

Replies

  • Anoop Kumar
    Anoop Kumar
    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.
  • patil.ashu01
    patil.ashu01
    Working in C#
    ianoop
    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.
  • rahul69
    rahul69
    patil.ashu01
    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.
    ๐Ÿ˜€ 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 ๐Ÿ‘.
  • patil.ashu01
    patil.ashu01
    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 ๐Ÿ‘.
    Thank You...
  • rahul69
    rahul69
    patil.ashu01
    Thank You...
    you're welcome...

You are reading an archived discussion.

Related Posts

I am working on a project, for which I want to measure the acceleration of machine. Is their any tool to do that or any formula which is based on...
I wish to know what are some of the alternative career options for a Marine Engineer apart from IES and MBA?
I am a graduate of Electrical/Electronics Engineering currently undergoing a one-year training in Process Automation,Control and optimization (PACO) at the Design office of Shell Petroleum Development Company In Port Harcourt...
Does transient response of a second order system depends upon the input magnitude ? I want to know let for unit step and 10 U(t) ,do the maximum overshoot or...
A majority of the defects circuit-board assembly are caused due to issues in solder-paste printing process or due to defects in the solder paste. There are many different types of...