File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes stack over flow exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "stack over flow exception" Watch "stack over flow exception" New topic
Author

stack over flow exception

bikasit babu
Greenhorn

Joined: Mar 29, 2012
Posts: 28


Can any body tell me.why exception occurs in this code.and what is the flow of execution?
Michael Novello
Greenhorn

Joined: Mar 03, 2013
Posts: 9
Part of your definition of the Manager5Part1 class is an instance of itself. This creates a never-ending loop, and ultimately a stack overflow, since non-local variables are kept on the stack.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Michael Novello wrote:... since non-local variables are kept on the stack.


It's local variables that are kept on the stack. Member variables go on the heap as part of their containing objects.

You're right that the infinite recursion is what's causing the overflow, but it's not the member variable. It's simply that, whether you have 0 local varaibles or 1000, every method call creates a new stack frame with, at the very least, the PC telling us where to resume execution after the method completes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: stack over flow exception