Win a copy of Head First Android this week in the Android 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Question

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can somebody tell me the answer for this..
Which of the following classes should have a finalize method?
A. A class that creates a 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.
I guessed A but the answer is A and C.
i Don;t accept answer c becos.. if this is the case as all classes are child of class Object then all classes should have finalize() method right. In that case answer B is also correct.
Could somebody clear me on this...
Thanks
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think C would be a valid answer for if there is a finalize method in a parent then it's there for a reason. Perhaps the programmer has written some special code to do something extraordinary. In that case, it might be safer to have something like this in the child:-
void finalize() {
super();
}
Just in case...but I take your point - it could be argued both ways I guess.
David.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having a finalize() method like you say is indeed a good idea if finalize() in a parent does something.
The problem here is that answer C implies answer B which is marked as incorrect. If answer C is correct, answer B must also be correct as indeed class Object, from which all other classes are implicitly derived, has a finalize() method.
Therefore, the stated list of correct answers to this question is incorrect. Either answer C is not correct, or answer C is correct and so is answer B (as the two are equivalent).
As a class is not required by the language standard to implement a finalize() method, I vote for the first alternative (only correct answer is A).
Were the wording of answer C different, stating that the finalize() method of some class inherited from is not empty, answer C would be correct, without implying answer B.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic