• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Shadowing static methods

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a thought for those who don't know it.
Private final methods can still be shadowed in
a sub-class. Are private static methods implicitly final?
Example:
The following piece of code compiles with no problems:

Any thoughts would be useful
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that private methods are essentially hidden from any would-be inheritors, as if they never existed in the first place.
B.test couln't call super.test(), for example.
Regards,
Brian Smith,
SCJP in training (as well)
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jay Hreich:
Are private static methods implicitly final?


Regardless of the fact that the method is static, this is what I found in the JLS, §8.4.3.3 final Methods:


A private method and all methods declared in a final class (�8.1.1.2) are implicitly final, because it is impossible to override them. It is permitted but not required for the declarations of such methods to redundantly include the final keyword.


Therefore, the method is implicitly final because it's private. The reason you can create a new method with the same name in the subclass is because private methods are not visible from subclasses.
I hope that helps,
Corey
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Private methods are not inherited. They're not part of the subclass.
That's why you can re-use the same name for a brand new method, that has no relationship with the method in the superclass, because it is not inherited. But this can lead to confusion, so it's best not to reuse names of private methods in your subclasses.
 
J Hreich
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all.
Great responses.
 
reply
    Bookmark Topic Watch Topic
  • New Topic