This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Q about Bill Brogden Exam

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have convinced me, Alton. I wonder if the API classes that create sockets call finalize.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic