Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection query

 
ramya ray
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
ramya ray
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much

I got it
 
Sireesha Mullapudi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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


Thanks
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic