0

I have implemented two interfaces with same method names and signatures in a single class then how the compiler will identify the which method is for which interface?

E.X:

           public interface Hourly{
              int calculate_salary();
            }

           public interface Fixed{
              int calculate_salary();
            }

           public class Employee implements Hourly, Fixed{   
              public static void main(String... args) throws Exception{   

              }

              @Override
              int calculate_salary(){  // from which interface Hourly or Fixed???
                return 0;
              }
            }

this problem has solution in C# but it did not work that way in java please help

thanks

2
  • It implements the method for both of them. Commented May 22, 2015 at 17:52
  • As an aside, you have a fundamental design problem here. Your class structure is saying that ALL your employees are BOTH hourly AND fixed. Commented May 22, 2015 at 18:02

1 Answer 1

2

There is no choice to be made.

There can only be one actual implementation of this method, and it will be called. The fact that the class implements two interfaces that both force it to have such a method doesn't meant that there must be (or can be) two such methods. The existence of the one method satisfies the conditions imposed by both interfaces.

Sign up to request clarification or add additional context in comments.

2 Comments

there should be some way to implement both interfaces in java
Only if you wanted to create the problem you are trying to ask about.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.