Java類、接口定義相關

今天的一點收穫ide

  
  
           
  
  
  1. /** 
  2.  * 如下程序編譯錯誤 
  3.  * Java類的成員變量會被自動初始化,但局部變量不會被自動初始化 
  4.  */ 
  5. public class Test { 
  6.     public static void main(String[] args){ 
  7.         int x; 
  8.         System.out.println(x); //The local variable x may not have been initialized 
  9.     } 
  10. /** 
  11.  * 如下定義正確與否
    */ 
  12. abstract public class TestProtected {}//Right! 
  13. final public class Test4{}//Right! 
  14.  
  15. //protected 不能用來定義類或接口 
  16. protected class Test{}//Error! 
  17.  
  18. //非嵌套類和接口都不能使用static定義 
  19. public static interface Test{}//Error! 
  20. static class Test{} //Error!  
  21. //注:只有在內部類時能夠定義靜態內部類
相關文章
相關標籤/搜索