• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface Doubt

 
Venkata Sirish
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter which method1() you are implementing.
You need to implement method1(), thats the main purpose of your class Interface1.
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear VenkataGuru Mitta,
Please do refer to this topic: multiple interface.
It discusses on the same topic.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Venkata Sirish
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for replying,
Can you please make it clear for me ...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic