java - What happens when you create a new object? -


ok, happens when this.

a a1=new a();  a2=new a();  a3=new a(); 

i upload 2 pictures on how imagine being like. can tell me picture true?

first picture: enter image description here

second picture: enter image description here

i thought first picture true, don't know, , suspect second true.

also, can explain me each side does? like, "a a1" , "new a()" do?

thanks.

new a() call no param constructor of class , create new memory object.

a a1=new a();  // new memory object created  a2=new a(); // new memory object created  a3=new a(); // new memory object created 

there 3 different objects getting created, second picture true.

for first picture true, declaration of references should this:

a a1=new a(); // new memory object created  a2=a1; // a2 points same memory object a1  a3=a1; // a3 points same memory object a1 

here 1 object(new used once) created 3 references point it.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -