This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why final keyword is accepted with private?

 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • 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.)
 
Seb Mathe
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about inner classes?
 
Seb Mathe
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic