public class Garbage
{
int a=0;
public void add()
{
int c=10+20;
System.out.println(c);
System.out.println(a);
}
public static void main(String args[])
{
Garbage obj=new Garbage();
System.gc();
System.out.println("Garbage Collected");
obj.add();
}
}
Above is a code in java used for garbage collection. object
obj has been created for the class Garbage and system.gc
method is called. Then using that object add method is
called.System.gc method if called the obj should be garbage
collected?
Answer Posted / madhu
Garbage Collector is called by the JVM. and it will collect
the objects which has no reference, in the above case obj
has reachability,so JVM won't force the garbage collector to
collect the obj object.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is hotjava?
What is the difference between overriding & overloading?
What is the requirement of thread in java?
What data type is string java?
What are the legal parameters?
what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread
What is purpose of applet programming?
Is hashset ordered java?
What is a parameter in java?
Difference between Linked list and Queue?
What kind of variables can a class consist?
What are the advantages and disadvantages of object cloning?
How do I enable java in safari?
What is javac_g?
What is a Null object?