public class ScopeExample {
static int globalCount = 10; // クラススコープ(フィールド)
public void testMethod(int param) { // メソッドスコープ(引数・ローカル変数)
int methodVar = 20;
if (methodVar > 10) {
int blockVar = 30; // ブロック変数のスコープ開始
System.out.println(blockVar + methodVar + globalCount);
} // blockVar のスコープ終了
// System.out.println(blockVar); // コンパイルエラー! スコープ外
}
}