This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
We have a clone() defined in Object class. If we try to execute a class overriding clone(), it throws CloneNotSupportedException. But if we implement Cloneable interface(which is a marker interface), everything goes fine. Now the question is, why do not we have a clone() in Cloneable interface rather then in Object class.
Is it in the Object only because we require a default implementation of a clone() and since Object is the superclass, so we cannot somehow implement that interface in Object class. But then Why do we require a Cloneable Interface at all. We can override its implementation in our subclass also.