my dog learned polymorphism*
The moose likes Beginning Java and the fly likes confused............ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "confused............" Watch "confused............" New topic
Author

confused............

Ganesh kumar
Greenhorn

Joined: Sep 06, 2005
Posts: 5
In the following code, how many objects will be eligible for garbage collection on the line with the comment //here

public class BettyAck {
public static void main(String argv[]){
BettyAck b =new BettyAck();
}
public BettyAck() {
Integer x = new Integer(10);
findOut(x);
Integer y = new Integer(99);
Integer z = y;
z = null;
findOut(y);
//here
}
public void findOut(Integer y){
y = null;

}
}



i'm jus not able to get it,can n e plzzz explain it to me
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
There are only three object created in this program. One is created in main() from the BettyAck class. The other two are created in the constructor for BettyAck from the Integer class. None of them will be avaiable for garbage collection since there are still references to all the objects. As soon as execution returns from the constructor back to main(), the two Integer objects will be available for garbage collection since all of the references to these two objects are local to the constructor. If this doesn't make sense, I suggest that you add System.out.println() calls to see what the values are of each variable at different parts in the code.

Layne


Java API Documentation
The Java Tutorial
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"Ganesh"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confused............