rendered paste bodyclass Zombie {
private int id;
public static int num;
public Zombie( int ident ){
this.id=ident;
}
protected void finalize(){
System.out.println("Zombie "+this.id+" is finalized.");
}
public static void main(String[] args) {
//Parse String to int
num=Integer.parseInt(args[0]);
if( num <= 0 ) {
System.err.println("usage: Zombie [integer] ");
System.exit(-2);
}
//create zombies
Object[] zombie = new Object[num];
for(int i=1;i<=num;i++){
zombie[i]= new Zombie(i);
}
//garbage collect
System.gc();
for(int j=1;j<=num;j++){
zombie[j].finalize();
}
}
}//Zombie