Rajarshi Rakshit

Greenhorn
+ Follow
since Jan 15, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajarshi Rakshit

Thanks for your reply Richa!

However, Java allows such memory assignments at class level (in fact I got one such example in the book 'Head First Java' page #239). So, in case you create (and assign) an object to a different class than X (at the class level), it works!
The problem here is: The constructor called is of the same class as the one in which the code exists in the first place. So there is a kind of recursive call!

However, it is the same with both the Versions (i.e. both are kind of recursive calls). But, only one goes for the stack overflow. Not sure why...
6 years ago
Hi All,

Following are two versions of the same program but the instance variable is initialized inside a method in one case; and other outside of it. However, when the program is run, only one of them gives a stack overflow (i.e. it runs infinitely) whereas the other does not. Please explain.



Version 1:


Version 2:
6 years ago