The static methods of the parent class in Java do not really have to be rewritten, but some people may do experiments to find that it is not a problem to rewrite the parent class static method in a subclass. Here, let me explain the details.
public class Parent {
public static void Add () {
System.out.println ("=========parent");
}
}
public class children extends Parent {
public static void Add () {
System.out.println ("=========children");
}
}
The above two classes did not find an error in the system and passed the test
public static void Main (string[] args) {
Children ch = new Children ();
Parent ch = new Children ();
Ch.add ();
}
The above test can be carried out, but attention is paid to the red callout part, the problem is here, the two quoted examples are new children (), if the static method can be rewritten, the results of the two sentences should be "=========children", But that is not the case, and both of them call their respective methods. So static methods are not rewritten, and their methods are independent.
Static methods of the parent class in Java cannot be overridden