File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes About Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About Interfaces" Watch "About Interfaces" New topic

About Interfaces

shankar reddy
Ranch Hand

Joined: Jun 04, 2007
Posts: 71
Can anybody clarify my doubt reagarding interfaces .

given program..

interface Left
int m1();
interface Right
void m1();
class MyClass implements Left,Right
public int m1()

if i am declaring like this ,, but i am getting compiletime errors.

what my intention is, i should implements the methods in those interfaces in my own (concrete)class. is there any alternative for that one.

i am very thankful if you resolve my problem.

Java Lover<br /> <br />Shankar Reddy <br />SCJP1.4 (88%)
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Well it really is worth you having a look in the FAQ to see if there is any information about Interfaces there, and to also check the Sun java site for information (

Having read your post again, I think the reason you are getting the error is because the method is named m1 in both interfaces, and the compilor dosnt know which interface's method (m1) you are trying to implement.

You cant have two methods named the same in one class unless you are overloading the method, ie changing the parameter list.


Hope that helps

[ July 04, 2007: Message edited by: Gavin Tranter ]

[ July 04, 2007: Message edited by: Gavin Tranter ]
[ July 04, 2007: Message edited by: Gavin Tranter ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You could easily implement two interfaces that declare identical signatures. When somebody uses your class, the interfaces promise the method will be there, and sure enough it is. This will surely confuse people if the two interfaces document different meanings for the signature. Say InterfaceA says "left() returns true if you should turn left now" and InterfaceB says "left() returns true if this object was left behind" and InterfaceC says "left() returns true if this object is a liberal".

But, your problem came about because the two interfaces have similar signatures that are not quite identical. If you implemented both, you'd have a duplicate method name because return type is not part of the unique method identifier. If you didn't implement both, you'd fail the contract on one interface.
[ July 04, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: About Interfaces
jQuery in Action, 3rd edition