File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use clone()

 
Nirvikalp Rao
Greenhorn
Posts: 27
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the link I gave you.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic