Naman Patidar wrote:@Rob : obj1.clone()==obj1 will always return false. colne() method creates a bit-by-bit copy of object so the objects will have different hashcodes.
Not necessarily. The API clearly states:
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:will be true, and that the expression:will be true, but these are not absolute requirements. While it is typically the case that:will be true, this is not an absolute requirement.
The following are therefore all valid implementations:
However, it is very usual to use super.clone(), and if all classes up the chain do that then yes, obj1.clone() != obj1 and all fields are copied.