*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes protected modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "protected modifiers" Watch "protected modifiers" New topic
Author

protected modifiers

Tusshar Fasate
Ranch Hand

Joined: May 21, 2008
Posts: 81
we know that the two methods in Object class are having protecetd modifiers.
Methods are
clone() and finalize()

Can anyone tell me
intention behind keeping them protected
and not public?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi!

Both methods have no meaningful implementation in class object. clone() even throws a RuntimeException if called on an object of type Object.

So I think these methods are kept protected to make it clear that they don't belong to the public API of class Object. But it's possible to promote them to public methods if you override them in a child class of Object and want to make them belong to the public API of your class.

Marco
Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Hi, good question. Since all Java objects implicitly extend the class Object anyway, this seems unnecessary, i.e. they might as well just make them public.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: protected modifiers
 
Similar Threads
Question from http://www.danchisholm.net
chapter 8: K & B
Help, exam in 2 days!
remembering access modifiers
Interface