This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.object  RSS feed

 
Punya Pratap Singh
Ranch Hand
Posts: 82
  • 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
Saloon Keeper
Posts: 6980
110
  • 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: 82
  • 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: 22185
38
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
Saloon Keeper
Posts: 6980
110
  • 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
Boost this thread!