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 type safety in java?
What is executor memory?
Which java ide is used the most?
What is private static in java?
what is meant by abstract class?
What is t in parametric equations?
Does java support function overloading, pointers, structures, unions or linked lists?
Is void a type?
What classes of exceptions may be caught by a catch clause in java programming?
Why wait and notify methods are declared in object class?
What is java used for on a computer?
Define "Access specifiers" in java.
What are exceptions
What is comparator in java?
What are bind parameters?