Originally posted by sura watthana: when object B is cloned from object A. then later after the execution of the programme, object A changes its properties or behaviour or both. My question is, will object B change too?
Yes. clone() performs a shallow copy, meaning only object references are copied but these object references in objects A and B both point to the same objects.
technically the answers are correct. But clone() should be implemented in such a way that changes in one object are not reflected by the other one. A typical way to override Object#clone() is to call super.clone() and then "fix" those fields that would otherwise cause this reflection.
You can relax on this one, the SCJP 1.4 exam does NOT cover the clone() method!
Yeah! Of course, it's good to understand clone(), but if you're just focusing on the exam you can put your precious study time to use in other areas. The areas that are typically the best places to put your emphasis are:
THREADS INNER CLASSES GARBAGE COLLECTION
There will be lots of questions on these topics, and they're pretty tricky!
Someone might do a search on an old topic from this forum entitled something like:
"Top ten things people think are on the exam, but aren't"
If you find it, resurrect it!
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)