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
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