This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
First of all you are invoking "eat" methods without "()" but I think thats a typo error.
It is absolutely "OK" to decalre an overridding method in subclass that doesn't throw an exception.
But in this program you are invoking the "eat" method using "Animal" class object. Due to polymorphism at runtime Dog class "eat" will get executed but since compiler doesn't know that and thinks that "animal" class eat method may throw an exception, it expects that you must enclose it in try-ctach block. That's the only problem.
Joined: Apr 03, 2006
ya sorry actually i missed those braces
so do u mean that for overriding a method with exception declaration we should either enclose the overriding method in a try catch block or declare those exceptions in the overriding method too ?