Quick revision
The short answer
Cloneable is a marker interface with no clone method: Object.clone is protected and only works if the class implements Cloneable, otherwise it throws CloneNotSupportedException. It makes a shallow field-by-field copy without calling any constructor, so invariants are skipped and final fields that hold mutable objects cannot be fixed up, and every subclass must call super.clone, cast, and handle a checked exception. We use copy constructors or static copy factories instead, such as new Order(other) or Order.copyOf(other); arrays are the exception, where clone() works well.
What to remember
In this answer, we saw that Cloneable declares no method and only switches on the protected Object.clone, which copies fields shallowly without running a constructor. That skips invariants, cannot deep-copy final fields, and forces every class in a hierarchy to override clone, call super.clone, cast and catch a checked exception. Copy constructors and static copy factories do the job with ordinary Java and explicit depth, and arrays remain the one place where clone() is the natural tool.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Cloneable is a marker interface with no clone method: Object.clone is protected and only works if the class implements Cloneable, otherwise it throws CloneNotSupportedException. It makes a shallow field-by-field copy without calling any constructor, so invariants are skipped and final fields that hold mutable objects cannot be fixed up, and every subclass must call super.clone, cast, and handle a checked exception. We use copy constructors or static copy factories instead, such as new Order(other) or Order.copyOf(other); arrays are the exception, where clone() works well.
Why this question is asked
Copying objects comes up whenever we need to hand out data without letting the receiver change ours, or take a snapshot of state. Java has had a built-in mechanism for it since version 1.0, and nearly every expert recommendation says not to use it. Interviewers ask why, because the answer shows whether we understand how the mechanism works rather than just repeating the advice. In this answer, we will look at how Cloneable and Object.clone actually work, go through the problems one by one with code, see the copy constructor and copy factory that replace them, and finish with arrays, the one place clone() is the right tool.
1How Cloneable and Object.clone Work
Cloneable is a marker interface: it declares no methods. Its only effect is on Object.clone, a protected native method. When clone is called, the JVM checks whether the object's class implements Cloneable. If it does, it allocates a new object of the same class and copies every field's value into it. If not, it throws CloneNotSupportedException.
Notice how unusual this is. The interface that enables cloning does not contain the method that does it, so having a Cloneable reference tells us nothing about whether we can call clone on it. A method that accepts a Cloneable cannot clone it, because Object.clone is protected. Every class that wants to be copyable must override clone, make it public, call super.clone, cast the result and handle a checked exception that should never be thrown.
2Problem 1: A Shallow Copy That Shares Mutable State
Object.clone copies field values. For a reference field, the value is the reference, so the clone and the original point to the same object.
To make a correct copy, the class must fix up every mutable field after super.clone returns, for example copy.items = new ArrayList<>(items). Forgetting one field, or adding a new mutable field later without updating clone, silently brings back the sharing.
3Problem 2: No Constructor and No Final Fix-Ups
Because clone creates the object without running a constructor, nothing the constructor normally does happens: no validation, no registration, no assignment of a unique ID. A class that guarantees each instance has a fresh ID from a counter, for example, produces clones with a duplicate ID.
Final fields make it worse. The fix-up in Problem 1 must assign to the field after the object exists, but a final field cannot be assigned outside a constructor.
So a class that wants both immutability guarantees, final fields, and a deep clone cannot have them. The clone mechanism is fundamentally at odds with final fields that refer to mutable objects.
4Problem 3: Subclasses Inherit the Burden
Every class in a hierarchy must cooperate. If any superclass's clone creates the copy with new instead of super.clone, subclasses get an object of the wrong class. Each subclass must also fix up its own mutable fields, and remember to do so whenever it adds one. And because clone is declared to throw a checked exception in Object, the try and catch above appear in every implementation, guarding against something that cannot happen.
Effective Java sums up the situation by advising that new interfaces should not extend Cloneable and new classes should not implement it, with the possible exception of arrays and final classes where the cost is low.
| Concern | Object.clone with Cloneable | Copy constructor or factory |
|---|---|---|
| Runs a constructor | No: invariants and validation skipped | Yes |
| Works with final fields | Not for deep copies | Yes |
| Checked exception and cast | Yes, in every override | No |
| Depth of the copy | Shallow unless fixed up by hand | Chosen explicitly per field |
| Can copy from an interface type | No | Yes, e.g. new ArrayList<>(anyCollection) |
5The Replacement: Copy Constructors and Copy Factories
A copy constructor takes an object of the same class and builds a new one from it, using ordinary constructor rules. A static copy factory does the same through a named method.
Everything that was awkward with clone is now normal. The constructor runs, so validation applies. Final fields are assigned once, with copies. There is no checked exception and no cast. The copy can even accept a different type: the collections framework's conversion constructors, such as new ArrayList<>(anyCollection) or new TreeSet<>(anySet), are copy constructors that take an interface. For immutable classes, we often need no copy at all, since sharing an immutable object is safe.
6Arrays: Where clone() Works Well
Arrays are the exception. An array's clone method is public, throws no checked exception, and returns the correct array type, so no cast is needed. For arrays of primitives, it is a complete, independent copy.
Notice the second example: for arrays of objects, clone copies the references, so the elements are shared. That is fine for immutable elements such as Strings, and needs a loop with element copies otherwise. Arrays.copyOf does the same job and also lets us change the length.
7Follow-up questions
Why did the JDK keep Cloneable if it is broken?
Removing it would break a great deal of existing code, including JDK classes that implement it, such as ArrayList and HashMap. So it remains supported, and the guidance is simply not to use it in new designs.
Is serialization a good way to make deep copies?
It works for serializable graphs but is slow, requires every class to be Serializable, bypasses constructors in a similar way to clone, and brings the security concerns of deserialization. Explicit copy constructors are clearer and much faster.
When is clone() acceptable on a class?
For a final class whose fields are primitives or immutable references, a public clone that just calls super.clone is correct and simple, because a shallow copy is a full copy. Even then, a copy constructor is usually just as easy and avoids the checked exception.
8Conclusion
In this answer, we saw that Cloneable declares no method and only switches on the protected Object.clone, which copies fields shallowly without running a constructor. That skips invariants, cannot deep-copy final fields, and forces every class in a hierarchy to override clone, call super.clone, cast and catch a checked exception. Copy constructors and static copy factories do the job with ordinary Java and explicit depth, and arrays remain the one place where clone() is the natural tool.
Open with
Cloneable is broken mainly because of how it is designed. It is a marker interface with no methods; it just switches on Object.clone, which is protected, so having a Cloneable reference does not even let you call clone.
Then, if they want more
To make a class copyable, you override clone, make it public, call super.clone, cast the result and catch CloneNotSupportedException, which can never actually happen.
Then the copy itself is a problem: Object.clone copies the fields shallowly without running any constructor, so mutable fields like lists are shared between the copy and the original, validation and things like unique ID assignment are skipped, and if those mutable fields are final you cannot fix them up after super.clone, so a deep copy and final fields do not mix.
Every subclass has to cooperate and remember its own fix-ups. Instead, I use a copy constructor, new Order(other), or a static factory like Order.copyOf(other), which runs normal constructor logic, works with final fields, has no checked exception or cast, and lets me choose for each field whether to copy deeply. It can even take an interface type, like new ArrayList<>(collection).
The exception is arrays: array clone is public, needs no cast and works well, though for object arrays it is still shallow.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why is Cloneable considered broken, and what do you use instead?": https://scrivio-interview-library.netlify.app/java/object-contracts/2b63766696/