Advertisement
Matteogoli

Untitled

Jun 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package prova;
  2.  
  3. import java.util.Iterator;
  4. import java.util.LinkedList;
  5.  
  6. public class Prova{
  7. static int counter = 4;
  8. private int value = 2;
  9.  
  10. public Prova() {
  11. value = ++counter;
  12. }
  13. public String toString(){
  14. return this.getClass().getName()+value+" ";
  15. }
  16.  
  17. public void finalize(){
  18. System.out.println("F"+value);
  19. }
  20. }
  21.  
  22. class G extends Prova{
  23. public static void main(String[] args) {
  24. LinkedList<Prova> x = new LinkedList<Prova>();
  25. Prova a1 = new G();
  26. G a2 = new G();
  27. Prova a3 = new Prova();
  28. x.add(a1); x.add(a3);
  29. a1 = null; a2 = null; a3 = null;
  30. Iterator<Prova> it = x.iterator();
  31. while(it.hasNext()){
  32. System.out.print(it.next());
  33. }
  34. System.gc(); System.runFinalization();
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement