DEVFYI - Developer Resource - FYI

I made my class Cloneable but I still get 'Can't access protected method clone. Why?

Java Interview Questions and Answers (part 2)


(Continued from previous question...)

367. I made my class Cloneable but I still get 'Can't access protected method clone. Why?

Yeah, some of the Java books, in particular "The Java Programming Language", imply that all you have to do in order to have your class support clone() is implement the Cloneable interface. Not so. Perhaps that was the intent at some point, but that's not the way it works currently. As it stands, you have to implement your own public clone() method, even if it doesn't do anything special and just calls super.clone().

(Continued on next question...)

Other Interview Questions