This week's book giveaways are in the Refactoring and Agile forums. We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line! See this thread and this one for details.
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.
posted 14 years ago
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