aspose file tools*
The moose likes Beginning Java and the fly likes Interface Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface Doubt" Watch "Interface Doubt" New topic
Author

Interface Doubt

Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
interface A{

public void method1();
}


interface B{

public void method1();
}

public class Interface1 implements A,B{

public void method1(){};

}
***********************************************************

As you see the above code , there are two interfaces with same abstract method ...

If a class need to implement both of the interfaces , then which of the method it is implementing ?

Is it common implementation for both of the abstract methods ???


Thanks in Advance....
Sheikh Sadiruddin
Greenhorn

Joined: Aug 10, 2007
Posts: 21
It doesn't matter which method1() you are implementing.
You need to implement method1(), thats the main purpose of your class Interface1.


SCJP 6 (80%) || SCWCD 5 (92%)
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear VenkataGuru Mitta,
Please do refer to this topic: multiple interface.
It discusses on the same topic.


With Best Regards,
Shyam Prasad Murarka
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

when you say you are going to implement an interface, ALL you are agreeing to is that you will have a method with that signature.

it's like if i told my mother I was going to name my son "fred", and then told my father i was going to name my son "fred". I don't need to have two children and name BOTH of them that, the same name works to satisfy both requirements.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Originally posted by Fred Rosenberger:
when you say you are going to implement an interface, ALL you are agreeing to is that you will have a method with that signature.

it's like if i told my mother I was going to name my son "fred", and then told my father i was going to name my son "fred". I don't need to have two children and name BOTH of them that, the same name works to satisfy both requirements.

Of course there would be a problem if you told your mother to call your first son "fred" and told your father you'd call your first son "john"

When implementing two interfaces with methods with equal signatures, make sure you keep to the contract of both, or otherwise don't implement one of the interfaces.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Thanks guys for replying,
Can you please make it clear for me ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface Doubt