aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MindQ's 37 mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "MindQ Watch "MindQ New topic
Author

MindQ's 37 mock

prasanna perera
Greenhorn

Joined: Oct 05, 2000
Posts: 16
Hi All!
37. Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
I know that d is wrong. What about the rest ?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by prasanna perera:
Hi All!
37. Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
I know that d is wrong. What about the rest ?

-------------------------------
a> true
the programmer can request to run the GC thread.
but the thread would run and garbage collect is highly unpredictable.
b>true
The finalize method is always called before an object is garbage collected. thus the finalize method is called only by the GC.the programmer cannot call the method
c> not sure
someone please guide me.
Any class that includes a finalize method should invoke its superclass' finalize method.
i think this is true since before any object is to be Gc, the super class object should also be Gc'ed.
i remember that super class constructor is called prior to the invoked class constructor. this means that when the derived class object is to be Gc'ed the base class object should be destroyed first.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
C is true also. If you have your own finalize method that cleans up things before they get GC, you want to call Object's finalize method to destroy the object after you did the part you wanted to do.
As for A, I think that is false, unless I am missing the meaning of invoked (which I may be). You can call the method explicitly System.GC(); but that doesn't mean the method will be invoked as it is unpredictable as to when the method will run. I have seen A worded a few different ways and it usually is false because of the unpreditable nature of GC. Anyone's thoughts?
chetan nain
Ranch Hand

Joined: Jun 21, 2000
Posts: 159

finally
1. false
2. true
3. false
4. false
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Not sure if I understand you post chetan, but finally is different than finalize. I think the answer is:
A. False
B. True
C. True
D. False
B and D I am postive about, C I feel pretty confident, and A I am uncertain.
Ira Jain
Ranch Hand

Joined: Sep 06, 2000
Posts: 70
I agree with Bill's answers .About A ,I think the answer should be false as just by calling the System.gc() we cannot be 100%sure that the garbage collector will be called at that particular moment.
Mukesh Rathod
Ranch Hand

Joined: Oct 11, 2000
Posts: 32
regarding option 1.
Thw API syas about gc:
Runs the garbage collector.
Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
The call System.gc() is effectively equivalent to the call:
Runtime.getRuntime().gc()

So It seems that choice 1 is correct one.
Shan Karawita
Ranch Hand

Joined: Oct 13, 2000
Posts: 83
Hello Prasanna,

This is not a reply to your problem.Sorry about that.
It seems you're a Sri Lankan.Are You ? If you are a Sri Lankan pl tell me when are you going to sit for the Test & How did you buy the Voucher & what is the cost of it.If you have bought the voucher from where did you buy it..

here is my email address...

dushan@jkcs.slt.lk
Thankx,
Shan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MindQ's 37 mock