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 / bhudeep
Java provides us one method System.gc()to call garbage
collection forcefully.But by calling System.gc() will not
ensure you that the object will be garbage collected.
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is meant by singleton class?
Write a java program to check if a number is prime or not?
Is null or empty java?
Is it possible to use Semaphore/ Mutex in an Interrupt Handler?
Can we override constructor?
How do you clear an arraylist in java?
Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
how to one war file class to another war file class?
take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).
What modifiers are allowed for methods in an interface?
Why packages are used?
How many threads does a core java have?
Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?
What do you know about the garbage collector in java?