wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes StackOverFlowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "StackOverFlowError" Watch "StackOverFlowError" New topic
Author

StackOverFlowError

Sandaru Jayathilake
Greenhorn

Joined: Sep 04, 2011
Posts: 2
Why does this give an StackOverFlowError in the line marked? When I make variable "a" static, it doesn't.

Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Sandaru Jayathilake wrote:Why does this give an StackOverFlowError in the line marked? When I make variable "a" static, it doesn't.


Why would you need "a" BankAccount inside a BankAccount instance ?
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Sandaru,
Your current code will keep on creating BankAccount Objects inside BankAccount objects till the Stack is full. That is why the error.
Thyagarajan Ramanujam
Greenhorn

Joined: Mar 24, 2008
Posts: 25
It is not due to multiple object creation in the for loop.

When you have a non-static object of a class as instance variable within the class itself, you will get this exception.

when you say new BankAccount(), BankAccount object is created which itself creates another BankAccount object and this goes on happenning and eventually you will end up with StackOverFlowError.

but when you declare the object as static, you have only one object. so you dont get that exception.
Sandaru Jayathilake
Greenhorn

Joined: Sep 04, 2011
Posts: 2
Thanks all!

What I wanted was just an application of static modifier!
To test it I tried creating instances here and there.
Now I understand what is wrong.

Thanks again!
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
Sandaru Jayathilake wrote:Thanks all!

What I wanted was just an application of static modifier!
To test it I tried creating instances here and there.
Now I understand what is wrong.

Thanks again!


Welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StackOverFlowError