/* staticフィールドと staticでないフィールドの違いを示す例 */ class StaticTest { int m=0; // オブジェクトごとの変数 static int n=0; // オブジェクト間で共有 } class Foo { public static void main (String[] args) { StaticTest x = new StaticTest(); x.m++; x.n++; // m と n をインクリメント System.out.println(x.m+", "+x.n); // 1, 1 StaticTest y = new StaticTest(); y.m++; y.n++; // m と n をインクリメント System.out.println(y.m+", "+y.n); // 1, 2 } }