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

say me when this eill actually happen.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are different types of arrays?

535


What restrictions are placed on method overriding in java programming?

544


What is the use of flag?

583


Is minecraft java edition free?

578


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?

586






What will happen to the exception object after exception handling?

579


Explain about object oriented programming and its features?

599


Difference between ‘is-a’ and ‘has-a’ relationship in java?

543


What is formatted output?

514


What is Garbage Collection in Java

613


How can a gui component handle its own events in java programming?

537


What is a file pointer?

516


What are Normalization Rules? Define Normalization?

551


What are the advantages of encapsulation in java?

553


Give few difference between constructor and method?

522