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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collection query" Watch "Garbage collection query" New topic
Author

Garbage collection query

ramya ray
Ranch Hand

Joined: Aug 11, 2006
Posts: 101
Please explain the answer of this question,i could not understand why A1A2A3 is printed instead of only A1 in answers.


Which of the following could be a result of attempting to compile and run the program?

a. A1A2A3A1
b. A0A0A0A0A1A2A3
c. A1A2A3A1A2A3
d. A1A2A3A1A1A2A3
e. A1A2A3A1A3A2A1
f. A0A1A2A3A1A2A3


Answer : a c d e

Please help
[ October 01, 2006: Message edited by: Barry Gaunt ]
Sac Anand
Greenhorn

Joined: Apr 21, 2006
Posts: 19
Hello Ramya,

Please explain the answer of this question,i could not understand why A1A2A3 is printed instead of only A1 in answers.


for loop will execute below mentioned 4 lines:

a0 = a0.other(); //that means a0 = a1 ... which will print A1
a0 = a0.other(); //that means a0 = a2 ... which will print A2
a0 = a0.other(); //that means a0 = a3 ... which will print A3
a0 = a0.other(); //that means a0 = a1 ... which will print A1

Hope this will help you understanding the answer.

Regards,
Sachin Anand
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
ramya ray
Ranch Hand

Joined: Aug 11, 2006
Posts: 101
Thank you so much

I got it
Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi,

I think the answer is only A.where iam making mistake?Can you please explain?


Thanks
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
It says which "could" be a result of attempting to compile and run the program.

The program will always print

A1A2A3A1

However in the main method after the call to m1(), we suggest the garbage collector run. So it could run and decide to collect any/all/none of the A objects (with names A1, A2, A3) in which case the finalize method would be called and they would print their name.
Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
I got it

Thanks
 
jQuery in Action, 2nd edition
 
subject: Garbage collection query