What happens when you create a new object?

前端 未结 10 1170
一个人的身影
一个人的身影 2021-02-10 18:53

Ok, so what happens when you do this.

A a1=new A();

A a2=new A();

A a3=new A();

I upload two pictures on how I imagine it being like. Can you

10条回答
  •  终归单人心
    2021-02-10 19:28

    2nd one is correct because whenever an object is created, it´s constructor is being called only once.

    Here the three different objects are created by the constructor calls. So the constructor is called three times.

    Whereas an ordinary object method may be called any number times for a given object, not the constructor.

提交回复
热议问题