0
public class ThTest1 {

    public static void main(String args[]) {

        System.out.println("Main started ");


        System.out.println("length: "+args.length);


        for (int i=0;i<args.length;i++){

           System.out.println("ARGS: "+i+"\t"+args[i]);
         }

         Thread th=Thread.currentThread();
         ThreadGroup tg= th.getThreadGroup();

         new Student();

         for(int i=0;i<10;i++)  {

              System.out.println(i+"\t"+th.getName()+"\t"+tg.getName());

         }

         System.out.println("Main completed");

    }

}

class Student {

    public void Finalize() {

        Thread th=Thread.currentThread();

        ThreadGroup tg= th.getThreadGroup();

        for(int i=20;i<40;i++) {

            System.out.println(i+"\t"+th.getName()+"\t"+tg.getName());
        }

   }

}
4

1 回答 1

4

finalize()应该在名称上匹配Object#finalize()以覆盖它并在最终确定期间实际使用。用小写命名它f

public void finalize() {

    Thread th=Thread.currentThread();

    ThreadGroup tg= th.getThreadGroup();

    for(int i=20;i<40;i++) {

        System.out.println(i+"\t"+th.getName()+"\t"+tg.getName());

    }
}
于 2013-11-04T17:54:53.290 回答