| Author |
need help
|
Anil Verghese
Ranch Hand
Joined: Oct 11, 2006
Posts: 155
|
|
What will happen when you compile and run the following code? class Box{ private int iVolume; Box(int iVolume){ this.iVolume=iVolume; } public void finalize(){ System.out.println("finalizing a Box"); } } public class EdGrundy{ boolean stop = false; public static void main(String argv[]){ new EdGrundy(); } EdGrundy(){ while(stop==false){ new Box(99); } } } [ October 12, 2006: Message edited by: Barry Gaunt ]
|
 |
Ali Gohar
Ranch Hand
Joined: Mar 18, 2004
Posts: 572
|
|
|
As there is no reference to new Box() object, it will be garbage collected and finalize message will be printed when this object is garbage collected.
|
 |
prashanth kumar
Ranch Hand
Joined: Mar 22, 2004
Posts: 162
|
|
Its an infinate loop... New objects are created as well as garbage collected forever till you halt JVM.. Rgds Prashanth
|
SCJP1.5(86%)<br />SCWCD1.4(95%)<br />SCBCD1.3(92%)<br />IBM 252
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
What happened when you compiled and ran the code?
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
 |
|
|
subject: need help
|
|
|