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

Thanks Namita

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What function extracts specified characters from a string?

567


What is the difference between static (class) method and instance method?

580


What is overloading and overriding in java?

664


What flag up means?

607


What mechanism does java use for memory management?

498






Is array size fixed in java?

546


What is the size of an array?

553


Why does my function print none?

524


What is native code?

540


What is jee6?

540


Is linked list a linear or non-linear data structure?

551


What about method local inner classes or local inner classes in java?

563


Explain about the security aspect of java?

579


How many bytes are there?

544


What is floor math?

521