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
Explain about object oriented programming and its features?
Why constructor has no return type?
How many bytes is a unicode character?
What is a super method?
What is final method?
How do you clear a method in java?
Why null value is used in string?
Are the imports checked for validity at compile time? Will the code containing an import such as java.lang.abcd compile?
What are the changes in java.io in java 8 ?
Can we extend immutable class?
What is a 16 bit word?
Explain enumeration in java?
Can private members of a base class are inheritable justify?
Is alive method in java?
What is memory leak and how does java handle it?