package test1021;

public class qwq {
    private static int n = 0;
    public qwq() {
        n += 1;
    }
    public static int getNumber() {
        return n;
    }
    
    public static void main(String[] args) {
        qwq q1 = new qwq();
        qwq q2 = new qwq();
        qwq q3 = new qwq();
        qwq q4 = new qwq();
        System.out.println("已生成对象个数为:" + qwq.getNumber());
    }
}

运行结果为:4.

posted on 2018-10-21 22:30  金猫大帝  阅读(121)  评论(0编辑  收藏  举报