Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 4
    Jon's suspicions (I didn't mark it as duplicate since answer simply confirms it based on JLS, while your question is more about why JLS is designed that way): stackoverflow.com/questions/26963828/…. About fields: they are not polymorphic (regardless if they are static or not so there is no point in limiting range of their changes). Commented Dec 18, 2015 at 23:23
  • 2
    Restored to pre-edited state. Just don't want people to understand the question as 'Why for fields is permitted and for methods is not'. Commented Dec 18, 2015 at 23:42
  • I preferred the edit, because I think this question is about the access modifier restrictions when hiding a method, in which case the static field example is misleading. I would phrase the question as, "Why does Java restrict the access modifier of a hiding method (since hiding is not polymorphic)?" Commented Dec 19, 2015 at 0:29
  • Jon Skeet hypothesizes in a comment, "that it's trying to avoid a situation where you have an explicit call to Subclass.foo() which is a private method which would normally resolve to Superclass.foo()." But I'm unable to see what problem that scenario presents. Commented Dec 19, 2015 at 0:38
  • 1
    It's interesting to note that when Java 8 added static methods to interfaces, this issue was avoided because those static methods are un-inheritable. Commented Dec 19, 2015 at 0:49