Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding Private method

 
umar hathab
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can we override private method?(I am able to override but i have some confusions)
Thanks.
A.umar
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Umar,
You can override private method with private, default(friendly), protected, or public method in subclass.
If you have default(friendly) method, it can override with friendly, protected or public method.
If you have protected method, it can override with protected or public method.
If you have public method, it can override only with public method.
Hope this help you
thanks
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3776
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only override something that you already have. private methods are not inherited by the subclass and so there is no question of overriding it.
You can obviously have a method in subclass with the same signature as the method in baseclass but it would have no relation to the base class method. It would be as independent as any other method with different signature.

------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No private methods can not be overrriden because they are not inhereted and because they are statically binded -as static ones-
If you place a method with the same signature as a private one declared in a superclass you won't obtain the polymorphic beheavior that is common for instance methods:

Here you will see method in Fahter is called. Compare it with the result if placing public instead
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic