Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what happen in memory when we assign one object to another object of same class in java?
Posted

1 solution

Very little, as the second object is merely a reference to the first. If you want a copy of the first element then you need to use the clone()[^] method.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Aug-11 22:39pm    
"First element" does not explain what's really going on. You probably mean the notion of shallow copy, when the members are copied as references, so there is not recursive (deep) cloning; anyway, it need some explanations.
--SA
Richard MacCutchan 7-Aug-11 4:35am    
That's why I added the link to the clone() method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900