URL :
http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html網上的一些關于內部類的概念是不完整的,還是看看SUN的文檔上的標準答案。
...
Like other members, a nested class can be declared static (or not). A static nested class is called just that: a static nested class. A nonstatic nested class is called an inner class.
- Nested class分為靜態Static nested class 的和非靜態的 inner class, 在SUN的眼里只有Nested Class!!
As with static methods and variables, which we call class methods and variables, a static nested class is associated with its enclosing class. And like class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class — it can use them only through an object reference.
- 靜態的Static nested class是不可以直接調用它的外部類enclosing class的,但是可以通過外部類的引用來調用,就像你在一個類中寫了main方法一樣。
...
As with instance methods and variables, an inner class is associated with an instance of its enclosing class and has direct access to that object's instance variables and methods. Also, because an inner class is associated with an instance, it cannot define any static members itself.
-非靜態類inner class 可以自由的引用外部類的屬性和方法,但是它與一個實例綁定在了以其,不可以定義靜態的屬性、方法(這點不是很理解,可能需要看JVM的類實現)
...
class EnclosingClass {
...
class InnerClass {
...
}
}
The interesting feature about the relationship between these two classes is not that InnerClass is syntactically defined within EnclosingClass. Rather, it's that an instance of InnerClass can exist only within an instance of EnclosingClass and that it has direct access to the instance variables and methods of its enclosing instance. The next figure illustrates this idea.

-圖形化的嵌入類與外部類的關系