• Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding private methods?  RSS feed

 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • 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?
 
V Srinivasan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • 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
=================================================
 
Simon Roberts
Author
Ranch Hand
Posts: 177
9
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Dilshad Syed
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a forum!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • 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!!
 
mansoor iqbal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess that is one greenhorn i am going to listen to!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!