• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

protected modifiers

 
Tusshar Fasate
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic