What happens when you create a new object?

前端 未结 10 1147
一个人的身影
一个人的身影 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 picture is correct.

    writing new is always create a newly object in heap.

    in real world comparison

    A a=new A();

    the above code can be similar to

    new A() ------------------ birth of a child

    A a ------------------ naming of that child(i.e. Ram,John)

提交回复
热议问题