wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Protected access for finalize and clone methods.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Protected access for finalize and clone methods.." Watch "Protected access for finalize and clone methods.." New topic
Author

Protected access for finalize and clone methods..

Rekha Rao
Greenhorn

Joined: Jan 23, 2001
Posts: 15
In the Object class, why are only the methods clone and finlaize have protected access ?
My understanding for providing the protected access modifier is to provide visibility for subclasses in different packages.
java.lang package is available by default and all classes extend the Object by default.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Rekha,
'protected' does give access to subclasses in other packages BUT only if the subclass participates in the creation of the protected object.
The two methods are protected to prevent any subclass of Object from calling them; they must be called from a direct subclass of the original object.
For example, if you have a ClassA object and a ClassB object, both of which implicitly inherit from Object you can't, from within ClassB call aObj.clone(). However, if ClassC is a direct subclass of ClassA then a ClassC object can invoke aObj.clone()
Hope that makes sense.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
Consider Paul's rocket mass heater.
 
subject: Protected access for finalize and clone methods..