posted 16 years ago
well you will have to handle it because you are using the super class reference to call the method. So at compile time the compiler will look at the method in the super class.
I have modified your code a bit
Now you might be saying that the method eat in class Animal actually doesn't throws any exception. But in it's throws clause it has a CHECKED exception (i.e. Exception). So it will force you to handle that exception whether it is actually being thrown or not. This is why call 1 will not work
Second thing about call 1. The actual method that will be called will be eat of dog class. And eat in dog doesn't thrown any exception. But the reference used to invoke eat is of type Animal. So the compiler will check the code of eat in Animal class and not dog class. Since it will find throws Exception there, it will force you to handle it.
call 2 will work as you are using dog reference to call it. Since the eat method in dog class doesn't throws any exception, so the call would be just fine and the compiler will not force you to handle any exception...