Forums Register Login

how to use clone()

+Pie Number of slices to send: Send
i created these classes and unable to find the problem,while i am trying to compile.
It says that clone() is protected in Object,even i read that Object is superclass for all classes we create.

the error is:

Any One tell me what is wrong with the code??
+Pie Number of slices to send: Send
Your duplicate() method adds nothing functionally to the clone() method. It's pointless.

As the error method it teling you, clone() is protected. Since it's not public, you can't just call it on any old object.


+Pie Number of slices to send: Send
Hi,
protected method can be invoke only in inheritance tree or inside a package.
So if you move your file to java.lang package, your code will compile fine.
Perhaps it is not good idea:)

Best reagards.
+Pie Number of slices to send: Send
You don’t have access to a protected member of Object in that class.
The problem is not about clone() but about protected access. You can read about clone() here. It’s the old edition. You can find the new edition by looking through our book review pages.
+Pie Number of slices to send: Send
 

Piotr Majcher wrote:. . . So if you move your file to java.lang package, your code will compile fine. . . .

We shall remember you on 1st April
+Pie Number of slices to send: Send
 

Piotr Majcher wrote:Hi,
protected method can be invoke only in inheritance tree or inside a package.
So if you move your file to java.lang package, your code will compile fine.
Perhaps it is not good idea:)

Best reagards.


thanks for the reply,please tell me can't we invoke protected methods out side the package if we inherit them.And
each class inherits "Object"
+Pie Number of slices to send: Send
Read the link I gave you.
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3687 times.
Similar Threads
clone() method in object class
[ Protected methods ] Don't understand error message
I have some vague concept about Cloneable....
clone() used on array and object
Protected methods in Object (clone, finalize) extra-protective
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:28:50.