类的静态字段和构造函数

 class task {
 static int A=0;
    public task()
    {    
        
        task.A++;
    }
    public static void main(String []args){
        task a = new task();
        task b= new task();
        task c = new task();
        task d = new task();
        task e = new task();
        task f = new task();
        task g = new task();
        task h = new task();
        System.out.print("已经创建了"+a.A+"个对象");
        
    }
}

posted @ 2018-10-21 17:31  忒儿  阅读(159)  评论(0编辑  收藏  举报