Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "need help" Watch "need help" New topic
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.
 
Don't get me started about those stupid light bulbs.
 
subject: need help
 
Similar Threads
Question from Examsimulator
Reg Garbage Collection
question from marcus green
When finalize() will be called?
GC question