We must write our code so that it is syntactically correct. It is also equally important to understand that our code does not create any ambiguity for the compiler. If we have such ambiguity, the language developers took care not to allow the compilation of such code.
A class inherits the behavior of its superclass. Access to static methods can be obtained simply from the class name, as well as from the instance. Suppose that there is a method with the same name and signature (except for the static
), calling the method in the instance will leave the compiler to throw. How will he decide what the programmer intends to do, which of the two methods does he intend to call? Therefore, the language developers decided that this case would lead to a compilation error.
According to
http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.8.2
If class C declares or inherits the static method m, then it is said that m hides any method m ', where signature m is the submission (§8.4.2) of signature m' in superclasses and superinterfaces C that would otherwise be available for code in C. This is a compile-time error if the static method hides the instance method.
public class Ov extends Am implements Inter { public static void main(String[] args) { Ov.fun();
source share