jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Object life cycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object life cycle" Watch "Object life cycle" New topic

Object life cycle

Sindu Ram

Joined: Aug 05, 2003
Posts: 6
I was recently asked a question about an object life cycle in Java, especially with regard to what happens when we do an
A a = new A();
and what goes to the stack and what to the heap.
Any info would be welcome.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Local variables are kept on the stack, while objects are kept on the heap. If this line of code is in a method, then the variable a is on the stack and the A object is on the heap; if it's a line of code at the top level of a class, then a is inside some other object on the heap, and the A is also on the heap.

[Jess in Action][AskingGoodQuestions]
Sindu Ram

Joined: Aug 05, 2003
Posts: 6
Thank you, Ernest..
I agree. Here's the link: http://aspose.com/file-tools
subject: Object life cycle
It's not a secret anymore!