| Author |
Jdiscuss question of the day - April 3, 2005
|
Neelima Chandran
Greenhorn
Joined: Jul 12, 2005
Posts: 12
|
|
Jdiscuss question of the day - April 3, 2005 Which of these statements are true? Select 1 correct option. a) Objects can explicitly be destroyed using the keyword delete. b) An object will be garbage collected immediately after the last reference to the object is removed. c) If object obj1 is accessible from obj2 and obj2 is accessible from obj1, then obj1 and obj2 are not eligible for garbage collection. d) Once an object has become eligible for garbage collection, it will remain eligible until it is destroyed. e) An object can be finalized only once. ------------------------------------------------------------- My answer was (c) The answer given is e) with the explanation if an object is resurrected in finalize() then it will never be finalized again. Can somebody elaborate on this please? Thanks, Neelima
|
 |
shyam ramineni
Ranch Hand
Joined: Jul 08, 2005
Posts: 43
|
|
Hi, Jdiscuss question of the day - April 3, 2005
Which of these statements are true? Select 1 correct option. a) Objects can explicitly be destroyed using the keyword delete. b) An object will be garbage collected immediately after the last reference to the object is removed. c) If object obj1 is accessible from obj2 and obj2 is accessible from obj1, then obj1 and obj2 are not eligible for garbage collection. d) Once an object has become eligible for garbage collection, it will remain eligible until it is destroyed. e) An object can be finalized only once.
Answer c cannot be correct as the question does mention any active references which refer to obj1 and obj2. If there are any live references which refer to either obj1 or obj2, then both of them will not eligible for garbage collection. Answer e is correct because finalize() method which every object inherits from java.lang.Object can only be executed only once.
|
<a href="http://hyderabaditeducation.com" target="_blank" rel="nofollow">http://hyderabaditeducation.com</a>
|
 |
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
|
|
c) If object obj1 is accessible from obj2 and obj2 is accessible from obj1, then obj1 and obj2 are not eligible for garbage collection. If both obj1 & Obj2 form a island of references, then it's eligible for GC. i.e If instance variables refer to each other, but their links to the outside is null, then these objects are eligible for garbage collection. e) An object can be finalized only once. It's True. Even D is true . Am i right ? [ July 12, 2005: Message edited by: Srinivasa Raghavan ]
|
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
|
 |
shyam ramineni
Ranch Hand
Joined: Jul 08, 2005
Posts: 43
|
|
Hi, Option D is not correct because, a Object which is eligible for Garbage collection can always be resurrected by the finalizer. In the finalizer block if we assign thisreference to some static variable, then we retrieve the object latter. This will prevent it from garbage collection. But, the next time when the object is eligible for garbage collection then the finalizer block will not be executed. You can refer Garbage Collection chapter from Khalid Mughal book for reference.
|
 |
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
|
|
|
thanks Shyam
|
 |
Neelima Chandran
Greenhorn
Joined: Jul 12, 2005
Posts: 12
|
|
Thanks a bunch for all your valuable points. Regards, Neelima
|
 |
 |
|
|
subject: Jdiscuss question of the day - April 3, 2005
|
|
|