×
クラスとオブジェクト
static フィールドによるインスタンス数のカウントと、static メソッドの呼び出し例です。
class Counter {
    static int count = 0; // クラス変数 (全インスタンスで共有)

    Counter() {
        count++; // インスタンスが作られるたびにインクリメント
    }

    static void printCount() { // クラスメソッド
        System.out.println("現在の生成数: " + count);
    }
}

public class Main {
    public static void main(String[] args) {
        new Counter();
        new Counter();
        Counter.printCount(); // インスタンスを生成せずに直接呼び出し -> 2
    }
}

もう少し詳しく