实现一个计数器,能够记录类创建了多少个对象

来源:互联网 发布:淘宝懒人鞋阿迪 编辑:程序博客网 时间:2024/05/01 22:30
public class Counter{    public static int num = 0;    public Counter(){        num++;        System.out.println("NUM = " + num);    }    public static void main(String[] args) {        Counter c[] = new Counter[5];        for (int i = 0;i < c.length;i++ )        {            c[i] = new Counter();        }    }}
0 0
原创粉丝点击