Quote:Original post by rip-off
i may be wrong, but doesnt clone return an Object?
Yeah, it does - I'm just an idiot and can't really get my brain around Java sometimes.
To expand upon the previous poster's reason as to why your code doesn't work (protected function compile error) is because clone is defined in Object as being protected (a scope which allows the containing class and all deriving classes access, and other classes in the same package). One of the 'rules' in Java is that you can't decrease the scope of a function/variable defined in a base class. By default, the scope of a function is what's called "package-level", which is between private and protected. So what the compiler's saying is that you're not allowed to decrease the visibility of Object.clone from protected to package-level.
The solution is, as the above poster mentioned, to define clone as public.
So the code (with these fixes) should look like this -
class Widget{ int member; public Widget(int val) { member = val; } public Object clone() { Widget w = new Widget(member); return w; }}
Hopefully that answered some more questions - sorry about the earlier screw-up [wink]