Java - How to resolve compiler error - clone() has protected access in java.lang.Object
If you are trying to clone an object in java and are getting the below compilation error -
Then the reason why you are getting the above compiler error is that you have not followed either 1 or both of the basic required steps for cloning an object in Java, which are -
clone() has protected access in java.lang.Object
Then the reason why you are getting the above compiler error is that you have not followed either 1 or both of the basic required steps for cloning an object in Java, which are -
- STEP 1 - The class of the object being cloned should implement
java.lang.Cloneable
interface. - STEP 2 - The class should override
clone()
method ofjava.lang.Object
class.