2018年10.21课后作业一
package trackobjectnum;
public class ObjectNum {
private static int n = 0;
public ObjectNum() {
n = n + 1;
}
public static int getNum() {
return n;
}
public static void main(String[] args) {
ObjectNum o1 = new ObjectNum();
ObjectNum o2 = new ObjectNum();
ObjectNum o3 = new ObjectNum();
ObjectNum o4 = new ObjectNum();
System.out.println("已生成对象个数为:" + ObjectNum.getNum());
}
}
private static int n = 0;
public ObjectNum() {
n = n + 1;
}
public static int getNum() {
return n;
}
public static void main(String[] args) {
ObjectNum o1 = new ObjectNum();
ObjectNum o2 = new ObjectNum();
ObjectNum o3 = new ObjectNum();
ObjectNum o4 = new ObjectNum();
System.out.println("已生成对象个数为:" + ObjectNum.getNum());
}
}