The Prototype pattern in Java is implemented by having a class implement the Cloneable marker interface and override Object's clone() method to return a copy of itself, which callers use instead of constructing a new instance from scratch.
A Configuration object that's expensive to rebuild can implement Cloneable and override clone() to return a copy that a caller can then tweak for a specific request, instead of re-running the original, costly initialization logic.
class Configuration implements Cloneable {
private Map<String, String> settings;
@Override
public Configuration clone() {
try {
Configuration copy = (Configuration) super.clone();
copy.settings = new HashMap<>(this.settings); // deep copy the map
return copy;
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}
}A concise interview answer is
I implement Prototype by having the class implement Cloneable and override clone(), calling super.clone() for the shallow copy and then explicitly copying any mutable referenced fields if I need a deep copy — that way cloning an existing instance replaces expensive re-initialization from scratch.
Last updated: 16 July 2026
Previous question: What is the difference between shallow and deep cloning in the Prototype pattern?
Next question: When would you use the Prototype pattern over creating a new instance?