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
Write a function to print Fibonacci series and Tribonacci series?
What is thread safe singleton?
What is the difference between equals() and?
What do you understand by garbage collection in Java? Can it be forced to run?
What happens if an exception is not handled in a program?
4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (
What do you mean by global variable?
What do you mean Abstraction in java?
Can we declare register variable as global?
How can I right-justify a string?
List two java ide’s?
What is the static block?
What happens when heap memory is full?
What is the purpose of stub and skeleton?
Why stringbuilder is not thread safe in java?