class MyClass 
{
   static String myName = "SCJP";
  
MyClass getMyClass() 
   {     
      System.out.println(myName);
      return null;     
   }   public static void main(String[ ] args) 
   {
     System.out.println( new MyClass().getMyClass().myName );
   }
}
输出为 
SCJP
SCJP
为什么?
The above method will not give any compilation error as at compile time, compiler sees the return type of getMyClass method as MyClass and calling myName on MyClass is valid at compile time.Also it doesn't give any runtime error which is not very obvious. Please note that a null reference may be used to access a class (static) variable without causing an exception. The static variable is called on the class itself and not on the object. Had the myName variable non-static, the above code at run time would give NullPointerException.Thus the above code will print SCJP twice: first inside the constructor (due to new MyClass() in "System.out.println( new MyClass().getMyClass().myName );" statement) and next on completion of the "System.out.println( new MyClass().getMyClass().myName );" statement.
这个解释我看不是很懂,请指教!