fork download
  1. /* package whatever; // don't place package name! */
  2. /* Exercise for CSN-103, IIT Roorkee */
  3.  
  4. import java.util.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public void finalize(){System.out.println("object is garbage collected");}
  12. public static void main(String args[]){
  13. Ideone s1=new Ideone();
  14. Ideone s2=new Ideone();
  15. Ideone s3=new Ideone();
  16. System.out.println(s1);
  17. System.out.println(s2);
  18. s1=s2;
  19. System.out.println(s1);
  20. s1=new Ideone();
  21. System.out.println(s1);
  22. s2=null;
  23. s3=s1;
  24. //s1=null;
  25. //s1=s3;
  26. System.gc();
  27. }
  28. }
  29.  
  30.  
Success #stdin #stdout 0.11s 33200KB
stdin
Standard input is empty
stdout
Ideone@2ff4acd0
Ideone@54bedef2
Ideone@54bedef2
Ideone@5caf905d
object is garbage collected
object is garbage collected
object is garbage collected