Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Why final keyword is accepted with private?

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why final keyword is accepted with private?

Private methods are not accessible outside of it's class, including to it's own subclasses. So, Overridding of a private method is not possible. Then, why Java accepts private & final kewords together in method declaration?

Note: Asking this question, because certain combination are not accepted by the java compiler like, e.g abstract & static keywords. (but don't discuss about abstract & static here, since the concepts are different in both.)
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's not a necessacity that the compiler checks for redundancies.

We can find another examples : why in interfaces can we use the keyword "public" for methods since methods are implicitly public ?

On the other hand, it's normal that the compiler complains if we declare an abstract method final, for example, because abstract methods can not be final.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about inner classes?
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Barry,

Do you think about this case ?



...compiles and prints :
A
A
AB

print() in B is not overriding print() in A.

(I had a doubt too about inner classes...)
[ October 12, 2005: Message edited by: Seb Mathe ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was thinking along the same lines (without the final). The inner class cannot override the outer class's private method, but it can call it in the inner class's version of the method. final on the outer method is also redundant in this case. I just threw the idea in for consideration.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic