I'm very confused with the following piece of code that I have which fails to compile -
This fails to compile due to the checked exception declaration in the superclass method eat()
I summarize the following rule of overriding concerning checked exceptions below
1) The overriding method MUST not throw any new or broader checked exceptions than those declared by the method in the superclass.
If I reason with this rule at the back of my mind, this code SHOULD compile. Furthermore, in the code the subclass object is assigned to a superclass reference which means in this case the subclass version of the eat method should execute successfully. Can anyone point me out of this dilemma?
I could have sworn I had seen the same code in a similar question only a few weeks ago, and I was mistaken about the Exceptions. But I can't seem to find it on a search. Maybe you will be more successful than me; try searching.
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