This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "stack over flow exception" Watch "stack over flow exception" New topic

stack over flow exception

bikasit babu

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

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

Joined: Jan 03, 2004
Posts: 6109

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:
subject: stack over flow exception
Similar Threads
Try catch flow
how it working?
one doubt
Program Logic.