Advertisement
Virajsinh

Java_05

Feb 7th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. //Write A Java Program to Explain Garbage Collection With finalize() Method
  2.  
  3. public class Ex5
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         Ex5 obj = new Ex5();
  8.         obj = null;
  9.        
  10.         Ex5 a = new Ex5();
  11.         Ex5 b = new Ex5();
  12.        
  13.         b = a;
  14.        
  15.         System.gc();
  16.     }
  17.    
  18.     //Optional Method
  19.     /* public void finalize()
  20.     {
  21.         System.out.println("Garbage Collection is Performed By JVM public");
  22.     } */
  23.    
  24.     protected void finalize() throws Throwable
  25.     {
  26.         System.out.println("Garbage Collection is Performed By JVM Protected");
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement