📄 countinstances.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 + -