permaculture playing cards*
The moose likes Beginning Java and the fly likes overriding method???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overriding method????" Watch "overriding method????" New topic
Author

overriding method????

raymond yadao
Ranch Hand

Joined: Jan 29, 2001
Posts: 88
Can an overriding method have no throws clause if the overridden method does have one?
vijay gardiner
Greenhorn

Joined: Jan 26, 2002
Posts: 14
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
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....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding method????
 
Similar Threads
Static method Overriding- confusion
Polymorphic Synchronized methods
Regarding overriding
for overloading..?
Overriding & Overloading