aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StackOverflowError error at Runtime  :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StackOverflowError error at Runtime  :(" Watch "StackOverflowError error at Runtime  :(" New topic
Author

StackOverflowError error at Runtime :(

Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
i'm getting a StackOverflowError at runtime....plz guide me why....


/*since 'an' is an instance reference variable for class Anonymous, i've created an instance of class Anonymous, in the main(), which accesses the instance variable 'an' and since it refers an object of the anonymous class instance, i call the method call() by using it.*/

plz help me out,,
Mihai Alexe
Greenhorn

Joined: Apr 13, 2005
Posts: 19
The problem with your code is that the Anonymous default constructor gets called somewhat "recursively". When you are calling the Anonymous constructor inside main() (i.e. new Anonymous()), the component objects get initialized first. That is, the constructor gets called again, because the an objects [of type Anonymous as well] needs to be assigned its value before the constructor finishes. There you go - an infinite constructor call chain - eventually ending in a StackOverflowException. I used the IBM JDK as well, and it refused to load my class - perhaps this compiler is a little "smarter" than the SUN javac


SCJP for Java 1.4<br />SCBCD for J2EE 1.3
 
 
subject: StackOverflowError error at Runtime :(
 
Similar Threads
Anonymous Classes
Can't identify the reason behind this code.
Anonymous inner class
Anonymous inner classes
Is there a way to instantiate anonymous inner class?