JAVA静态方法形式上可以重写,但从本质上来说不是JAVA的重写。因为静态方法只与类相关,不与具体实现相关,声明的是什么类,则引用相应类的静态方法(本来静态无需声明,可以直接引用),看下例子:
- 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();  
-          }  
- }  
 
以上输出的结果是:A
                           B
                           A
                           D
非静态方法 按重写规则调用相应的类实现方法,而静态方法只与类相关。java静态方法的重写,为什么不能?
原文:http://blog.csdn.net/litong09282039/article/details/46317181