_、美元符 $ 開頭,後續可含數字。abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return strictfp short static super switch synchronized this throw throws transient try void volatile while
goto、const 為保留字,現不使用。
| 類型 | 宣告位置 | 生命週期 | 預設值 |
|---|---|---|---|
| 區域變數 | 方法/建構子/區塊內 | 隨方法調用創建/銷毀 | 無 (必須顯式初始化) |
| 實例變數 (成員) | 類中、方法外、無 static | 隨物件 new 創建、GC 回收 | 0/false/null |
| 靜態變數 (類變數) | 類中、static 修飾 | 類載入時創建、類卸載銷毀 | 0/false/null |