aspose file tools*
The moose likes Beginning Java and the fly likes which interface method it has implemented in class A. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "which interface method it has implemented in class A." Watch "which interface method it has implemented in class A." New topic
Author

which interface method it has implemented in class A.

kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
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

Joined: Aug 15, 2001
Posts: 140
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

Joined: Aug 05, 2005
Posts: 3689
    
  16
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.


Joanne
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


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
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
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

Joined: Aug 23, 2005
Posts: 5
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.


Naveen Vooka<br /><a href="http://www.devsquare.com" target="_blank" rel="nofollow">www.devsquare.com</a><br />DevSquare - Online Application Development
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which interface method it has implemented in class A.