Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cloneable

 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do we have to study Cloneable interface for scjp5 ?
 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> the objectives of scjp 5 doesn't mention it
> I think theres only 1 thing to remember about cloneable interface. For implementing cloneable you dont have to define any methods; marking a class cloneable is just marking a flag for the class which enables its objects to be cloned. api of cloneable inteface shows that there are no methods.
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method clone is available in every class because it is a public method in Object class.

Just implement Cloneable interface and you can use the method but if you call clone method without implementing the above mentioned interface, CloneNotSupported Exception is thrown.

Other thing to note about is deep cloning where in each object is carbon copied so that each reference of the clone refers to a new object instead of the objects referred by corresponding reference variables in the original copy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic