You're not really declaring a local variable in this method. You're simply creating a new object (on the heap, where all Java objects live) inside the method, then returning a reference to that object.
But suppose that you did declare a local variable that pointed to that object...
In this case, the variable "fred" would be destroyed when the method exits, but the object that fred pointed to would still exist on the heap. At this point, whether that object is eligible for garbage collection depends on whether there are any other references to it. And since getRabbit returns a Rabbit, it's likely that when you call the method, you will assign the Rabbit reference to a variable outside of the method. For example...
Rabbit albert = getRabbit();
Here, a new Rabbit would be created (on the heap) and the local variable fred would reference it. The fred variable would be destroyed when the method exits, but the variable "albert" would still be pointing to the object.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: May 25, 2006
Thanks so much. You guys are el33t!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com