老紫竹群中(_愛若蕪緣…提供此题

静态方法不能被覆盖,如下程序,结果为

Parent
Parent

执行child.getName()的时候会再次的进入parent.getName());

package test;

public   class   Test2   
{ 
 public   static   void   main(String[]   args)   
 {
  Parent   parent   =   new   Parent(); 
  Parent   child   =   new   Child(); 
  System.out.println(parent.getName()); 
  System.out.println(child.getName());
 }
}

class   Parent   
{ 
 public   static   String   getName()   
 { 
  return   "Parent "; 
 } 
} 

class   Child   extends   Parent
{ 
 public   static   String   getName()
 { 
  return   "Child "; 
 } 
}

 

黑色头发  http://heisetoufa.iteye.com

如果发现本文有误,欢迎批评指正