File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.object

 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Object class is availble to each and every type of class and iterface,then why some methods of Object class are protected ?

please explain .

 
Stephan van Hulst
Bartender
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain in what circumstances you would use protected access?
 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you want to give access in package and subclasses to out of the package.then protected is used as access specifier.
 
Paul Clapham
Sheriff
Pie
Posts: 20164
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. And therefore those protected methods were declared protected so that those rules would apply to them.
 
Stephan van Hulst
Bartender
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Members should be as private as possible.

clone() is a mechanism that should only be used if a subclass of Object allows it. That's why it's protected. A subclass should determine whether it makes it public.

finalize() would ideally be package private, but subclasses have to be able to provide additional cleanup code, therefore the method is made protected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic