File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Inherited methods in Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Inherited methods in Interfaces" Watch "Inherited methods in Interfaces" New topic
Author

Inherited methods in Interfaces

ravi
Greenhorn

Joined: Apr 11, 2005
Posts: 2
If an interface inherits two methods without overriding and differ only in their exceptions then how to implement them in a class that implements the subtype interface. Plz illustrate with an example.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough. You can change your display name here. Thanks!

Now, to answer your question: if you can't write a single method that satisfies both exception specifications, then you simply can't implement both interfaces in one class, end of story. This issue is specifically described in Gosling and Arnold's "The Java Programming Language."


[Jess in Action][AskingGoodQuestions]
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Two methods cannot be declared with only difference being the exception declaration, as this amounts to a duplication of methods which is disallowed.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Rex Farmer
Greenhorn

Joined: May 05, 2005
Posts: 1
I think he's talking about two interfaces with identical methods on them that differ only by their exceptions. That's perfectly legal, but their implementation must be the same method, and the exception signature of any implementation must be compatible with both superinterfaces.

In general, it's always OK to take exceptions out of method signatures for subtype relationships, but you can't add any in.

You wanted examples:



Note that in this example, it's not OK for D.xyz to declare either ParseException or IOException.
 
jQuery in Action, 2nd edition
 
subject: Inherited methods in Interfaces