Originally posted by Arun Maalik:
The problem with the above code that it's going in the infinite loop why and when i am removing the code at line 2 its working fine otherwise infinite loop why?
Line 2 in the code results in creating an object of the same class for the object created in line 4.
This object in turn is forced to create another object wirthin it, and so on. This process will repeat itself leading to infinite loop.
This is similar to calling a recursive method without giving the exit condition. Thus, in the above code, you are recursively creating objects of the same class, without any condition to stop the process it goes into infinite loop.
But the execution stops at some point of time,atleast in
Java 5, giving an error.
Removing line 2, removes the above cycle of events. So, the code does not
go into infinite loop.
[ March 02, 2007: Message edited by: Thulasi Prasanna ]