Choose Your Language

Thursday 27 March 2014

garbage collection in java

public class GarbageCollectionSample {
    public static void main(String ar[]){      
        GarbageCollection garbageCollection=new GarbageCollection("BLACK");
        System.out.println(garbageCollection.displayColor());
        garbageCollection.finalize();
        System.out.println(garbageCollection.displayColor());    
    }
}
class GarbageCollection {
private String color;

    public GarbageCollection(String color) {
        this.color = color;
    }
        public String displayColor(){   
         return color;
        }
    @Override
    public void finalize() {
            this.color="No Color";     
    }  
}

output:
BLACK
No Color

No comments:

Post a Comment