• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

which interface method it has implemented in class A.

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic