Originally posted by Ernest Friedman-Hill:
I don't know what "don't participate in inheritance" means. It is indeed true that static methods are not polymorphic, and you can't override them and get polymorphic behavior. But static methods are inherited in the sense that they're available amongst the child class's methods; you can call a static method using the child class's name, or using an instance of the child class, or without qualification in the body of a child class.
Therefore, if you define another method with the same name, you must follow the rules that apply to method overloading. It's not legal to have two overloaded methods with the same name and argument types but different return types, and that's the problem you're seeing here.
Actually I believe they must follow the same rules as
overriding which are specified in 8.4.8.3 of the JLS 3rd ed. With static methods instead of overriding an inherited method with the same signature it is said to
hide the method. However, they must both follow certain rules one of which is that:
If a method declaration d1 with return type R1 overrides or hides the declaration of another method d2 with return type R2, then d1 must be return-type substitutable for d2, or a compile-time error occurs. Furthermore, if R1 is not a subtype of R2, an unchecked warning must be issued (unless suppressed (�9.6.1.5)).
That's what the compiler is complaining about.
Originally posted by Naseem Khan:
If you can access any member of superclass by its simple name in subclass
without prefixing super, then that member is considered to be inherited.
This is the simple test.
No. A static method may be hidden by another static method in which case while the method is still inherited it would not be accessible by it's simple name.