This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes need help to resolve protected clone() error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help to resolve protected clone() error" Watch "need help to resolve protected clone() error" New topic
Author

need help to resolve protected clone() error

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
For the following code, I see this error:

CloneTest.java:66: clone() has protected access in java.lang.Object
cloned.address = (Address) address.clone();



Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
It is a bit confusing. I believe you need to override the method in your Address class. You can leave it as protected and just return super.clone() if that's acceptable. Also, bring your salt shaker as I can't recollect ever using protected nor do I use Cloneable so it's entirely possible I'm spewing misinformation as it's not something I generally bother with on either count.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Address should implement Clonnable interface and should override the clone method to make this work.


Rahul Bhattacharjee
LinkedIn - Blog
 
jQuery in Action, 2nd edition
 
subject: need help to resolve protected clone() error
 
Similar Threads
protected behaviour of clone method is surprising !
Is it me or just Eclipse... JEdit too...
User-defined objects in collections
Polymorphism example
Question regarding Cloneable interface and Subclasses