⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countinstances.java

📁 21Java教程的全部源代码 北京邮电大学出版
💻 JAVA
字号:
public class CountInstances {
    private static int numInstances = 0;

    protected static int getNumInstances() {
        return numInstances;
    }

    private static void addInstance() {
        numInstances++;
    }

    CountInstances() {
        CountInstances.addInstance();
    }

    public static void main(String[] arguments) {
        System.out.println("Starting with " +
            CountInstances.getNumInstances() + " instances");
        for (int  i = 0; i < 10; ++i)
            new CountInstances();
        System.out.println("Created " +
            CountInstances.getNumInstances() + " instances");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -