Why can't I access the clone()
method for any object?
All objects extend Object
and clone
is in Object
with the protected
modifier. protected
makes method accessible for subclasses. Why can't I access clone
?
Asked
Active
Viewed 32 times
0

E_net4
- 27,810
- 13
- 101
- 139
-
1Are you trying to call `clone()` from a subclass, or from somewhere else? Seeing your code would help. See: [mre]. – John Kugelman Oct 23 '21 at 23:42
-
@JohnKugelman I think the issue is that because `clone` is declared in `Object`, technically every call to `clone` is from a subclass. – kaya3 Oct 24 '21 at 00:14
-
1*"I do know that what I wrote above is wrong and ask you to correct me instead of downvoting."* - The downvotes are not because you were wrong. They are because the question was not properly researched before asking. Research that *should* have found the existing Q&A (and that its assumptions were wrong). And it was a downvote on the question ... not on you. (You will only get votes personally if you stand to be elected as a moderator!) But since you asked to be corrected, this is me correcting you. – Stephen C Oct 24 '21 at 01:08
-
2The primary purpose of votes on questions and answers is quality control on the Q&A knowledge-base. – Stephen C Oct 24 '21 at 01:09