Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.object

 
Punya Pratap Singh
Ranch Hand
Posts: 81
  • 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
Posts: 6321
78
  • 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
  • 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
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • 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
Posts: 6321
78
  • 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