This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "protected modifiers" Watch "protected modifiers" New topic

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

Joined: Mar 07, 2007
Posts: 1294


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.

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:
subject: protected modifiers
It's not a secret anymore!