• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Cloneable

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do we have to study Cloneable interface for scjp5 ?
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic