• 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

Public Vs Protected methods in object class

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)...
 
reply
    Bookmark Topic Watch Topic
  • New Topic