public class Test {
        public static void run() {
            int n=0;
            for(int i=0;i<=10;i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Test t=new Test();
                n++;
                System.out.println(n);
            }
    }

    public static void main(String []args) {
        run();
    }

}

用函数run()创建对象,每隔一秒运行一次,使用n计数。

posted on 2018-10-21 11:24  雨过山  阅读(86)  评论(0)    收藏  举报