• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which interface method it has implemented in class A.

 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A implements B,C
{

//how do i know which interface method will be called here.
ex()
{
}

}

interface B
{
ex();
}

interface C
{
ex();
}

Is there any way to know which interface method it has implemented in class A.
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public interface C
{
void ex();
}

public interface B
{
void ex();
}

public class A implements B,C
{
public void ex()
{
System.out.println("aaaaaaaaa");
}

public static void main(String args[])
{
A a = new A();
a.ex();
}
}

Is there any way to know which interface method it has implemented in class A.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has implemented both.
Implementing interface B means that A must have a method void ex(). It does.
Implementing interface C means that A must have a method void ex(). It does.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the doc for interface B says ex() turns the lights off and the doc for interface C says ex() turns the lights on, some of the clients of class A are going to be disappointed. With luck two interfaces with matching syntax (method names) will promise matching semantics (what happens) but if not your implementing class will have to manage the conflict somehow.
 
Norm Radder
Bartender
Posts: 1366
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A suggestion: Instead of asking a question about what would happen IF I WRITE THIS CODE and execute it?
Write the code and see what happens.
Then come back and tell us and we'll all know.

Just a thought.
 
Naveen Vooka
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
With luck two interfaces with matching syntax (method names) will promise matching semantics (what happens) but if not your implementing class will have to manage the conflict somehow.


That will depend on the actual problem at hand. You can't resolve the
conflict always. Like the lights on/off thing.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right! Managing the conflict might mean convince somebody to change one of the interfaces or remove the need to implement both in one place or look for another job.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic