• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Garbage collection query

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
ramya ray
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much

I got it
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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


Thanks
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic