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


Please Help Members By Posting Answers For Below Questions

What is an example of a boolean?

801


Why object class is super class for every class in java?

798


If you do not want your class to be inherited by any other class. What would you do?

781


Why is serialization required?

738


What is an empirical question?

766


What is difference between class and object in java?

749


Describe the syntax of multiple inheritance? When do we use such an inheritance?

827


What is 32 bit float?

762


What is string data type?

747


What is ‘is-a ‘ relationship in java?

796


What is the final class modifier?

762


What are the advantages of arraylist over arrays?

799


Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)

1087


What is static class

824


What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?

2206