File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help
 
Similar Threads
Question from Examsimulator
Reg Garbage Collection
GC question
When finalize() will be called?
question from marcus green