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*

2
  • Thanks for the answer. I can understand if a class does not allow same method name for two methods, even if one is instance and other is static. But I fail to understand why it does not allow a sub class to have an instance of same name. Especially considering the fact that static methods are not inherited, cannot be overridden. And yet, Java allows subclass to have same name as parent class static method, which is called information hiding, but not overriding. Commented Dec 30, 2015 at 7:32
  • Suppose some other code in your class B contains a call testStatic();. How is the compiler supposed to figure out whether you meant this.testStatic(); (an instance method call) or A.testStatic(); (a static method call)? Note that even the JLS uses language suggesting that static methods are inherited. It's legal to access A.testStatic() using B.testStatic() (although lint tools will warn about that). It's just a guess, but I think the language designers thought that allowing instance methods to hide static methods as you describe was just too hard to get right. Commented Dec 30, 2015 at 7:45