If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class. A compile-time error occurs if a static method hides an instance method.
It is possible for a class to inherit more than one method with the same signature. Such a situation does not in itself cause a compile-time error. There are then two possible cases:
* If one of the inherited methods is not abstract, then there are two subcases:
o If the method that is not abstract is static, a compile-time error occurs.
o Otherwise, the method that is not abstract is considered to override, and therefore to implement, all the other methods on behalf of the class that inherits it. A compile-time error occurs if, comparing the method that is not abstract with each of the other of the inherited methods, for any such pair, either they have different return types or one has a return type and the other is void. Moreover, a compile-time error occurs if the inherited method that is not abstract has a throws clause that conflicts (�8.4.4) with that of any other of the inherited methods.
* If all the inherited methods are abstract, then the class is necessarily an abstract class and is considered to inherit all the abstract methods. A compile-time error occurs if, for any two such inherited methods, either they have different return types or one has a return type and the other is void. (The throws clauses do not cause errors in this case.)
Originally posted by Sujatha Kumar:
I have read in few articles that the static methods cannot be inherited.
To prove to myself about what i have read,
I created a Parent Class with a static method say MethodA()
then i Created a Child Class inheriting the Parent Class
But It was a surprise for me when I saw that,
I was able to inherit the static method defined in the Parent Class??
Can anyone of you, share your thoughts on this topic....
[ November 10, 2004: Message edited by: Sujatha Kumar ]
Originally posted by Nikhil Vasaikar:
It can also be overridden in the child class.
Originally posted by Vladas Razas:
I think they could/should disallow this kind of shadowing in compiler. We can always chose another method name for inherited class.
Originally posted by Ilja Preuss
No, it cannot be overridden