wood burning stoves*
The moose likes Java in General and the fly likes java.lang.object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.lang.object" Watch "java.lang.object" New topic
Author

java.lang.object

Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
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

Joined: Sep 20, 2010
Posts: 3605
    
  14

Can you explain in what circumstances you would use protected access?
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
when you want to give access in package and subclasses to out of the package.then protected is used as access specifier.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Correct. And therefore those protected methods were declared protected so that those rules would apply to them.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3605
    
  14

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.object
 
Similar Threads
Is Any clas like already pre-compiled
Will every class inherit the object class?
Difference between an Object and Instance.
java.lang.Object
Factory