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 / bhudeep

Java provides us one method System.gc()to call garbage
collection forcefully.But by calling System.gc() will not
ensure you that the object will be garbage collected.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of join method?

1033


Difference between operator overloading and function overloading

1069


What is meant by call by reference?

1009


How many bits is a string?

1005


What is the hashcode () and equals () used for?

1038


What is an accessor?

1688


What is a modifier?

1521


What are the types of inner classes (non-static nested class) used in java?

1065


Can we write multiple catch blocks under single try block?

1087


How to create an immutable class?

1109


Why synchronization is important?

1028


What modifiers may be used with an inner class that is a member of an outer class in java programming?

1103


Can we override tostring method in java?

971


When the constructor of a class is invoked?

1034


What is mean by collections in java?

1181