Originally posted by johnx smithx:
The book says that the code will not compile because of the Exception declared on the Animal eat() method.
That's because the compiler checks the reference variable type (the left side of the equal sign) and sees "Animal a" and Animal eat() method can throw an Exception (despite of the Dog2 instance being referred to - after all it can be Animal or any kind of Animal in runtime).
and as Ilja said, "a.eat() can throw an exception, but the main method does not - and it doesn't catch it, either." So, it won't compile.
[ June 06, 2008: Message edited by: Rodrigo Tomita ]