• Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange Output  RSS feed

 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While running my java program,I am getting strange output.Have a look at code.

Output is given below-

at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)

// Lots for of these stacktraces

at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)
at ImplClass1.<init>(MyClass3.java:17)
at ImplClass.<init>(MyClass3.java:11)

Can anybody guess what is reason behind such type of output?
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create an instance of ImplClass. This has a field of type ImplClass which is initialized to an instance of ImplClass1. But because ImplClass1 extends ImplClass, this instance too has a field of type ImplClass, which is initialized. And that too has a newly initialized instance of ImplClass1. And that too. And that too. After a while the JVM simply gives up and throws a StackOverflowError.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've removed a part of the stacktrace making the topic more scrollable.
 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob..........I'v got it.......
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!