This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Can an overriding method have no throws clause if the overridden method does have one?
vijay gardiner
Greenhorn
Joined: Jan 26, 2002
Posts: 14
posted
0
Hi, Yeah you can do that, but the vice versa would end in compilation error. If I'm right in interpreting ur doubt, here goes my example : class A { public void Test() throws IOException { } } class B extends A { public void Test() {} } In the above example, Test() with no exception thrown overrides the Test() which throws exception, which is perfectly alright. Vijay This
Jennifer Wallace
Ranch Hand
Joined: Nov 30, 2001
Posts: 102
posted
0
Yes, there is no need to declare the exception declared in the throws class of the overriden method. From JLS,
A method that overrides or hides another method (�8.4.6), including methods that implement abstract methods defined in interfaces, may not be declared to throw more checked exceptions than the overridden or hidden method.
The Restriction is only on not throwing any more checked exception than the original overriden method. Less is acceptable....