Is this the way Constructor in Java allocates memory?

前端 未结 5 1754
遥遥无期
遥遥无期 2021-01-07 04:45

Default constructor is automatically called after an object is created.

But in Java when we allocate memory using new operator i.e. classname obj = new classna

5条回答
  •  伪装坚强ぢ
    2021-01-07 05:07

    If we consider an example like

    classname obj = new classname();
    

    classname obj initialize the object and new classname(); allocates memory location for the object. If you have a constructor, then the constructor is called, otherwise default constructor is called.

提交回复
热议问题