How the static constructor is used in object creation?

patil.ashu01

patil.ashu01

@patilashu01-wqV4iY Oct 21, 2024
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

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn 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.
  • patil.ashu01

    patil.ashu01

    @patilashu01-wqV4iY Jan 9, 2013

    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

    @rahul69-97fAOs Jan 10, 2013

    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

    @patilashu01-wqV4iY Jan 10, 2013

    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

    @rahul69-97fAOs Jan 10, 2013

    patil.ashu01
    Thank You...
    you're welcome...