A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Take Control of Upgrading to Yosemite
Take Control of Automating Your Mac
this week in the
Joined: Nov 13, 2005
Mar 21, 2007 00:58:00
Suppose I want an object to be cloned.So I would implement a public/protected Object clone() method inside its class.My question is whether I need to compulsorly specify that this class implements Cloneable or is it optional?
Joined: Mar 05, 2007
Mar 21, 2007 01:22:00
So I would implement a public/protected Object clone() method inside its class.
You need not implement Object clone() method inside your class. You just need to make a call.
To answer your second question, yes it is mandatory for the class to implement Cloneable interface.
And best way to figure out whether it is mandatory or not is just to write a
program and run it.
Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
Joined: Oct 13, 2005
Mar 21, 2007 03:00:00
You probably would wish to implement a clone() method. There is recent discussion
on this thread
about how one might do it.
subject: Cloneable interface
what is the need for a DTO / VO to implement Cloneable interface
Doubt in data encapsulation !!
Why finalize() and clone() are protected in Object class
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014