Link to home
Create AccountLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

clone method

Hi,

I read cloneable interface is tagging interface. Class must override Clone() metjod declaring it as public where as Clone() method declared as protected in Object class. Any ideas, suggestions, links, resources, sample code highly appreciated. Thanks in advance
Avatar of Valeri
Valeri
Flag of Bulgaria image

The most important about cloning in java is that by default clone method makes shallow copy and does not make a Deep copy of object!!! The only way to override clone() method of the object is to implement Cloneable interface, otherwise clone() method will throw "CloneableNotSupportedException".
this article explayns everything about cloning in java:
http://javainnovations.blogspot.com/2008/06/cloning-of-java-objects.html
Hi gudii9,
There is a mistake in the above article. This line:
"Deep copy means if your object contains references of other objects or collections, it will not make a copy of those referenced objects and will use same references as was in origianl objects."
should be
"SHALLOW copy means if your object contains references of other objects or collections, it will not make a copy of those referenced objects and will use same references as was in origianl objects."
Avatar of gudii9

ASKER

>>>Deep copy means if your object contains references of other objects or collections,

sorry i did not uderstand clearly. Can you please elaborate
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account