In the Prototype pattern, shallow cloning copies an object's field values but leaves reference-type fields pointing at the same shared objects as the original, while deep cloning also copies those referenced objects so the clone is fully independent.
Key Points: • Shallow clone copies primitive fields by value and object references as-is, so both objects share the referenced instances. • Deep clone recursively copies every referenced object, producing a completely independent object graph. • Mutating a shared reference in a shallow clone will affect the original object too, which is a common source of bugs. • Deep cloning is more expensive in time and memory but is safer when independence is required. • Java's default Object.clone() performs a shallow copy; deep copying must be implemented manually or via serialization.
Example: If a Person object has a shallow-cloned Address field, changing the cloned person's address.city also changes it for the original person, because both objects still point at the same Address instance; a deep clone would give the copy its own separate Address object.
Interview Tip: A concise interview answer is:
"Shallow cloning copies field values but leaves object references shared between the original and the clone, so mutating a referenced object affects both. Deep cloning recursively copies those referenced objects too, giving you a fully independent copy — Java's default clone() is shallow, so deep copying needs to be implemented explicitly."