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 an example of a boolean?
Why object class is super class for every class in java?
If you do not want your class to be inherited by any other class. What would you do?
Why is serialization required?
What is an empirical question?
What is difference between class and object in java?
Describe the syntax of multiple inheritance? When do we use such an inheritance?
What is 32 bit float?
What is string data type?
What is ‘is-a ‘ relationship in java?
What is the final class modifier?
What are the advantages of arraylist over arrays?
Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)
What is static class
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?