• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

When do we need Cloning ?

- You need to Clone an Object is when it is a parameter or return value of one of your public methods. If it is a parameter that you save somewhere, then you don't want the caller to be able to modify it later.So you save a copy of the Object.
Likewise, if you are returning an Object that is part of your class's internal state, you need to return a copy instead so that callers can't accidentally or deliberately change that internal state.

- when you might want to Clone is when you need to modify an Object, but you don't know who else might have a reference to it. So you make a copy and modify that.
I don't have the money to clone my racehorse. It was just a thought. Clones would be great if it is possible to clone, say, a dinosaur or something from the past to study. [that does sound cruel... but interesting..