As far as overriding is concerned, eat method in Dog2 class is throwing fewer checked exceptions isn't it. So that should compile fine. But the code is not compiling as you've written in your comment as well. Its not compiling because the compiler only knows that a variable is of type Animal which throws an Exception so you need to handle it. The compiler doesn't know that at runtime the eat method of Dog2 class will be called which doesn't throw any exception...
Only instance methods can be overridden as it is clearly documented on page 139 of the same book.
In the example the the Animal eat() method is not static .
polymorphic invocation of happens at runtime of which the compiler knows nothing about.
Joined: Mar 03, 2011
Ok, So the compiler only sees "Animal a" and since Animal class' eat() method throws an exception, the compiler expects you to either "Handle/Declare it"
But @run time, since Dog2 version is invoked, it runs fine.
Sorry for the typo brother, the method is not static!!
Yes, polymorphic invocations are done by the JVM!!
Compiler only sees "Animal a"