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 / namita
First We cannot force the garbage collection to garbage the
object. Garbage collection can never be forced.
So by calling System.gc() will not ensure you that the
object will be garbage collected.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is return code?
Explain about join() method?
What does provide mean construction?
When is the finally clause of a try-catch-finally statement executed?
What is the difference between interface & abstract class?
Define how does a try statement determine which catch clause should be used to handle an exception?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?
How do you implement polymorphism in our day to day life?
Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.
What is the relationship between class and object?
What is a java object and java application?
What is variable explain with example?
Explain exception chaining in java?
Can we override constructor?
What are the 8 data types in java?