• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Protected access for finalize and clone methods..

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic