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.
Unlike the other methods in Object, neither are meant to be called directly on an instance of Object, they are intended to be overridden by subclasses.
By default clone() throws an exception if the class does not implement Cloneable. If you want to make a class cloneable, the standard pattern is to implement Cloneable and override clone(), making it public.
finalize() is not meant to be called by the programmer - it's called by the garbage collector. So there's no need for it to be public.
Joined: Feb 23, 2011
i am not clear about the answer.
i want to know that what would have happened if these methods would have been public.
If you search, you will find this question comes up frequently. The clone() method is not meant to be called until it has been overridden; then it can become public. The finalize() method should never be called; only the JVM should call it, so it does not need to be public.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com