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.
A subclass should be able to be used in anywhere its superclass can be used. (See "Liskov Substitution Principle"). In this case any code that uses a Parent2 reference expects to be able to call myMethod(int) without having to handle an IOException. Your subclass method can't be more restrictive than the method it is overriding. It can however be less restrictive and throw fewer checked Exceptions than the method that it is overriding. [ July 02, 2007: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Oct 31, 2006
Thanks Garrett !
Does this mean we can not use throws clause with implementor class where same method is used in multiple interfaces with different exceptions?
What if developer wants to use more restrictive checked exceptions on the method?
Joined: Jan 17, 2006
Does this mean we can not use throws clause with implementor class where same method is used in multiple interfaces with different exceptions? Thats correct.
What if developer wants to use more restrictive checked exceptions on the method? That is simply not allowed in Java.