aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Public Vs Protected methods in object class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Public Vs Protected methods in object class" Watch "Public Vs Protected methods in object class" New topic
Author

Public Vs Protected methods in object class

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 309
hi,
What is the reason for having some methods public and some protected in Object class.

In order to use the protected members, the Object class has to be inherited and then only base class objects can call the protected methods, and not super class object. Why is there such kind of restriction.


SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

Naresh Chaurasia wrote:only base class objects can call the protected methods, and not super class object.

Base class and super class are the same thing for me

Anyway, finalize and clone methods are protected in Object class. finalize is protected so that you don't explicitly call finalize on instances of a class. finalize method is supposed to be called by garbage collector not us. clone is protected because objects of a class can be cloned if the class implements cloneable interface. So by making the method protected, you can't call the method on every class that you want (because calling clone method on object of a class that doesn't implement Cloneable interface generates a CloneNotSupportedException)...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Public Vs Protected methods in object class
 
Similar Threads
java.lang.object
Doubt in the class Object
Why finalize() and clone() are protected in Object class
protected methods of java.lang.Object
accessing protected methods from non-derived classes