posted 22 years ago
Q4
You are writing a set of classes related to cooking and have created your own exception hierarchy derived from java.lang.Exception as follows
Exception
+-- BadTasteException
+-- BitterException
+-- SourException
Your base class, "BaseCook" has a method declared as follows
int rateFlavor(Ingredient[] list) throws BadTasteException
A class, "TexMexCook", derived from BaseCook has a method which overrides BaseCook.rateFlavor(). Which of the following are legal declarations of the overriding method?
a. int rateFlavor(Ingredient[] list) throws BadTasteException
b. int rateFlavor(Ingredient[] list) throws Exception
c. int rateFlavor(Ingredient[] list) throws BitterException
d. int rateFlavor(Ingredient[] list)
THE GIVEN ANS:acd.
I think the checked Exception which override method throws should be the same with supper class or the subclass Exception of the supper Exception ,concern the case the BitterException are not among the two case above ,so I think c is not right.
am I right?somebody correct me if I am wrong.
MY ANS:ad.