This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes reference variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reference variable" Watch "reference variable" New topic
Author

reference variable

pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137


what does the above code do??
does it make one reference variable a and assign it a new Animal object during each iteration. and in the end we have 20 Animal objects added to aList and a refers to the last one and other 19 left without any reference??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39529
    
  27
Yes, 20 Animal objects are created, and after the loop is done, they are all eligible for garbage collection since they are not referenced.


Ping & DNS - updated with new look and Ping home screen widget
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Ulf
pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137
thanks all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reference variable
 
Similar Threads
Overloaded question
overload and override method question
Object type Vs Reference type
Head First Java Five Minute Mystery p. 268
which version of method is actually called ? the reference one or actual object one ?