This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple interface

 
Jitendra Jha
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have made 2 different interfaces which have the same method prototype(method declaration).when i implement both in a class,i see that they work fine.i want to know which method is used(from interface 1 or from interface 2)?how do i check?

package Dump1;

interface interfaceExp
{
int a=1;

void Name();

}


package Dump1;

interface interfaceExp1
{
int a=1;

void Name();

}



package Dump1;

class interfaceExpdemo implements interfaceExp,interfaceExp1
{
public void Name()
{
System.out.println("Hello");
}

public static void main(String args[])
{
interfaceExpdemo ied=new interfaceExpdemo();
ied.Name();
}
}
 
Henry Wong
author
Marshal
Pie
Posts: 20834
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to know which method is used(from interface 1 or from interface 2)?how do i check?


Unfortunately, there is no "which method" as there is only one implementation, that satifies both interfaces. From the method, there is no mechanism to tell what the reference type that was used to call the method was.

Henry
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and more importantly, it doesn't matter. The interfaces don't have any implementation, they are only a "contract" that the class that does implement the interface will have the contained method signature.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pete stein:
and more importantly, it doesn't matter


Yet it may. If interface A expects method xyz() to do one thing, and interface B expects it to do another, the contract with one or other of the interfaces needs to be broken.

It doesn't matter as far as the compiler is concerned, but the situation is still one to be avoided.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Yet it may. If interface A expects method xyz() to do one thing, and interface B expects it to do another, the contract with one or other of the interfaces needs to be broken.

It doesn't matter as far as the compiler is concerned, but the situation is still one to be avoided.


Thank you for that clarification.
 
Jitendra Jha
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the light of the above discussion,the question still remains,how do we know which method is being used.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As there can be only one method, there is no amibiguity. What is ambiguous is which intention the method implements, which is why the situation shold be avoided.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic