The statement from the book is correct. There are two things in it.
1) Note that the author says "CAN" and not "MUST":
Overriding finalize methods can limit the range of throwables to unchecked exceptions. Further overridden definitions of this method in subclasses will not be able to throw checked exceptions
Notice here that NumberFormatException is an un-checked exception
(i.e. some subclass of RuntimeException). Now in class A we have
done exactly this: we have limited the range of the Throwables
to unchecked exceptions only ( the signature of finalize() in
Object was : "protected void finalize() throws Throwable" )
2) The second thing which the author means is that if you do
that in A then in all classes which derive from A you will not
be able to declare something like:
This is quite clear because B can not override any method from
its superclass and make it throw "more" checked exceptions than
the superclass. And as finalize in A throws no checked exceptions
at all class which directly or indirectly derive from A can not
throw any checked exceptions as well.
So the answer to the question is:
finalize() can throw checked exceptions but only
of classes which are either the same classes or are subclasses of
the checked exceptions which super.finalize() has declared to throw.
Hope this makes things clearer.
[ February 13, 2006: Message edited by: Peter Petrov ]
[ February 13, 2006: Message edited by: Peter Petrov ]
[ February 13, 2006: Message edited by: Peter Petrov ]
[ February 13, 2006: Message edited by: Peter Petrov ]
[ February 13, 2006: Message edited by: Peter Petrov ]