This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q about Bill Brogden Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q about Bill Brogden Exam" Watch "Q about Bill Brogden Exam" New topic
Author

Q about Bill Brogden Exam

Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443

Question 26:
Which of the following classes should have a custom finalize method?
a. All class that creates socket
b. All classes
c. Any class that extends a class having a finalize method
d. Any class that creates an array of primitive values
Answer: a

I don't understand why a is correct? The finalize() method is unreliable so if it is implying that the class can close the socket from the finalize() method, then that is a wrong place to do it.
I would say that the 'correct' answer should be c because finalize() may get executed, and the finalize() method inherited by the subclass may not work on the subclass.
[ August 15, 2003: Message edited by: Alton Hernandez ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
You have convinced me, Alton. I wonder if the API classes that create sockets call finalize.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
You mistake the intent of having a finalize method - it should not be intended as the routine method for cleaning up but as the "last chance to fix things" in case of something odd happening. Thats why you will find finalize used in the standard Java library in places like java.io.FileInputStream.
That way if you are sloppy at closing your FileInputStream - the finalize method may be able to keep you from running out of file handles.
Having the full source to the standard libraries is a great resource for those studying the language. "Use the Source"
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Q about Bill Brogden Exam