Hi, 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. Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal
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.