• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

stack over flow exception

 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can any body tell me.why exception occurs in this code.and what is the flow of execution?
 
Michael Novello
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic