• 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

overriding private methods?

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RHE states "The rules for overriding can be summarized as follows:
A private method may be overridden by a private, default, protected or public method."

How can this be? A private feature may only be accessed by the class that owns the feature. Even if the subclass has a method with the same signature, it is not overriding the private method, is it?
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
may be overridden... looks vague. Private method is absolutely private for the class that belongs to. What I understand is the signature i.e. valid identifier of a private method can be freely used by any sub class, by doing so the approach differs for accessing a private method of a particular class and really overriding is not taking place here and hiding is happening here. To prevent this we have to use final modifier. Please correct me if my understanding is wrong.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Overriding a method means that by creating a method with the same signature, the method in the parent class is replaced. Thus if a descendent class does not have a method with the same signature the method in the parent class will be called. As a private method is not inherited this definitition cannot be true, thus a private method cannot be overridden, though of course it can be replaced.
Marcus
------------------
http://www.jchq.net Mock Exams, FAQ, Tutorial, Links, Book reviews
=================================================
Almost as good as JavaRanch
=================================================
 
Author
Posts: 285
12
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, this is imprecise. Sorry. The point being made is that you can declare methods in subclasses that have identical method names and argument lists. That's not the same as overriding.
What happens is more properly likened to overloading. There is no dynamic binding involved, the decision about what method to execute is made statically at compilation time, not at runtime.
So, my mistake, I'll be looking to correct this in the next printing. Thanks for pointing it out.
Cheers,
Simon
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What a forum!
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon, You've come to inspire us!!!
I hope you don't mind if I gossip to the family about your help!!
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i guess that is one greenhorn i am going to listen to!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic