The Java programming idea says that "only normal method invocations can be polymorphic". To be blunt, a static method cannot be implemented to override this polymorphism.
Java static methods can be rewritten in the form (as long as the subclass does not add the @override keyword modifier), but in essence it is not a Java rewrite. Because static methods are related only to classes, not to specific implementations, and to what classes are declared, the static methods that refer to the corresponding classes (which are statically non-declarative and can be referenced directly) are given in the following example:
Java code
- Class base{
- static void A () {System.out.println ("a"); }
- void B () {System.out.println ("B");}
- }
- Public class Inherit extends base{
- static void A () {System.out.println ("C"); }
- void B () {System.out.println ("D");}
- public static void Main (String args[]) {
- Base b=new Base ();
- Base c=New Inherit ();
- B.A ();
- B.B ();
- C.A ();
- C.B ();
- }
- }
class base{static void A () {System.out.println ("a"); } void B () {System.out.println ("B");}} public class Inherit extends base{static void A () {System.out.println ("C"); } void B () {System.out.println ("D");} public static void Main (String args[]) {base b=new base (); Base c=new Inherit (); B.A (); B.B (); C.A (); C.B (); }}
The result of the above output is: A B a D non-static method calls the corresponding class implementation method according to the rewrite rule, and static The State method is only relevant to the class.
overriding issues with static key in Java