Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Can a source file contain more than one class declaration?

918


Is there any sort function in java?

998


What is an enumeration?

1012


What is a ternary operator in java?

948


Give a brief description of java socket programming?

917


What is foreach loop in java?

963


Explain importance of throws keyword in java?

948


When will we use them?

987


What is basic syntax?

991


Difference between ‘is-a’ and ‘has-a’ relationship in java?

955


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

987


What is the role of garbage collector in java?

911


how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application

2105


can used Protected Class outside Function.?

1062


What is a method in coding?

998