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 / madhu
Garbage Collector is called by the JVM. and it will collect
the objects which has no reference, in the above case obj
has reachability,so JVM won't force the garbage collector to
collect the obj object.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Can substring create new object?
What are the various access specifiers for java classes?
What are static variables and functions?
What does percent mean in java?
make a method which any number and any type of argument and print sum of that arguments.....
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
Can we override the private methods?
What is the purpose of nested class in java?
Which is faster set or list in java?
What technique can be employed to compare two strings?
What is generic class?
How to do encapsulation in java?
Can we pass a primitive type by reference in java? How
What are the concepts of 'OOPS'?
How do you escape json?