This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
The clone method is defined as a protected method in java.lang.Object class and every class in Java extends Object. Since subclass can inherite the protected method of its superclass, every class is suppoed to inherite clone method from Object class.
But when I want to invoke clone method of a object, the compiler reports the following error:
It may seem weird that you need to override clone(), but the key is that you must give it public access to be able to call it from a different class. Protected methods are inherited by the subclass, but they aren't visible outside the class or subclass.