aspose file tools*
The moose likes Beginning Java and the fly likes how to use clone() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to use clone()" Watch "how to use clone()" New topic
Author

how to use clone()

Nirvikalp Rao
Greenhorn

Joined: Feb 14, 2012
Posts: 27

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??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.


Piotr Majcher
Greenhorn

Joined: Jan 14, 2012
Posts: 5
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
Nirvikalp Rao
Greenhorn

Joined: Feb 14, 2012
Posts: 27

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"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Read the link I gave you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use clone()