"静的メソッドに加えて、静的クラスもあります。これらについては後ほど詳しく説明します。今のところは例だけを示します。"

例:
public class StaticClassExample
{
    private static int catCount = 0;

    public static void main(String[] args) throws Exception
    {
        Cat bella = new Cat("Bella");
        Cat tiger = new Cat("Tiger");

        System.out.println("Cat count " + catCount);
    }

     public static class Cat
    {
        private String name;

        public Cat(String name)
         {
            this.name = name;
            StaticClassExample.catCount++;
         }
     }

}
2
タスク
Java Syntax,  レベル 6レッスン 7
ロック未解除
Code entry
Your attention, please! Now recruiting code entry personnel for CodeGym. So turn up your focus, let your fingers relax, read the code, and then... type it into the appropriate box. Code entry is far from a useless exercise, though it might seem so at first glance: it allows a beginner to get used to and remember syntax (modern IDEs seldom make this possible).

" Cat オブジェクトは必要なだけ作成できます。ただし、静的変数の場合はそうではありません。静的変数のコピーは 1 つだけ存在します。"

「クラス宣言でstatic修飾子を使用する主な目的は、 CatクラスとStaticClassExampleクラスの間の関係を制御することです。考え方はおおよそ次のとおりです。Catクラスは StaticClassExample オブジェクトにリンクされておらず、インスタンスにアクセスできません (非static) StaticClassExample クラスの変数。

「クラス内にクラスを作成できるということですか?」

「はい。Java ではそれが可能ですが、今はあまり考えないでください。将来、さらにいくつかのことを説明するときに、より明確になります。」

「そうだといいですね、リシ」