• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

garbage collection

 
Ranch Hand
Posts: 5415
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it True:
An overriding finalize() method in any class can always throw checked exceptions

I think Yes as overridden method throws Throwable
TIA
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you are correct. Since the overridden method declares it can throw a Throwable, it basically can throw *anything*. So a subclass would be able to throw anything as well, checked or unchecked.
Although, since the exception thrown by finalize() is ingored, it really doesn't matter what it throws!!
Rob
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rob: also it can choose to throw nothing. right ?

Originally posted by Rob Ross:
I believe you are correct. Since the overridden method declares it can throw a Throwable, it basically can throw *anything*. So a subclass would be able to throw anything as well, checked or unchecked.
Although, since the exception thrown by finalize() is ingored, it really doesn't matter what it throws!!
Rob

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

yes,it can choose to throw nothing.
regards.
maulin.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, what Maulin said!
Rob
 
R K Singh
Ranch Hand
Posts: 5415
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
but Khalid says NO ...
Que No 8.4 from Khalid.
explanation I am not getting ??
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ravish kumar:
Hi
but Khalid says NO ...
Que No 8.4 from Khalid.
explanation I am not getting ??


What does this mean? Do you have a question, or a quote?
I didn't understand you!!

Rob
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ravish,
i c what u mean. i interpreted the explanation KM gives like this,
u can make the class throw only unchecked execptions.
now, if u try to subclass this kind of class u CAN'T THROW CHECKED exceptions.
so, the option (c) may be wrong. it depends upon the parent class u r making child of...
but the option (d) is true for any class.
hence , (d) is the right answer.
regards
maulin.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, it would be nice if someone would actually post the question and answers you are talking about so the rest of us don't have to try to guess what they are!!! :roll:
Rob
 
R K Singh
Ranch Hand
Posts: 5415
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q. Which of these stsmts are true?
Select all valid answers:
a) The compiler will fail to compile code that explicitly tries to call the finalize()
b) The finalize() must be declared with protected accessibility.
c) An overriding finalize () in any class can always throw checked exceptions.
d) The compiler will allow code that overloads the finalize() name
e) The body of the finalize() can only access other objects that are eligible for garbage collection.

hate typing from book ...
AW are you happy now Rob ?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, thank you Ravish
Rob
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone please post what the correct responses should be? I believe D is the only correct one
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think both C and D are correct.
C: see Rob's reply
D: u can overload anything.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate the word "always" because it means you just have to find ONE example that causes that to not be true, and the whole item is then not-true.
case in point:
c) An overriding finalize () in any class can always throw checked exceptions.
I just thought of a situation where this is not true.

IF you override the finalize() method, AND in overriding it you do not specify any throws declarations, then in the body of your finalize() you throw a new checked exception, it won't compile. So C is true IF you make the assumption that you are declaring any check exceptions you are throwing, but I don't think you can make that assumption. So this one failure causes C to be false. I didn't think about this case originally.
My argument is still correct however, that since the Object class's version of finalize() declares it throws a Throwable, ANY overriding version of this method can throw any exception at all it wants, provided of course it declares the exceptions it throws in the method declaration with a 'throws' clause
So I think D is the only correct answer.
Rob
[ January 23, 2002: Message edited by: Rob Ross ]
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic