java static イニシャライザ
静的初期化ブロックは、括弧{}で囲まれ、前にキーワードstaticが付いているコードブロックです。
static イニシャライザは、クラスロードされる際に、実行されるブロックです。
staticフィールド
staticフィールドはプログラムが実行される時に生成され、すべてのインスタンスが共有します。
実装
public class StaticTest {
public static void main(String[] args) {
System.out.println(AAA.m);
}
}
class AAA {
static {
m = 300;
}
static int m = 100;
}
実装結果
100
Process finished with exit code 0