| 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
|
 |
 |
|
|
subject: Protected access for finalize and clone methods..
|
|
|