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

Bilal Maqsood
  • 1,163
  • 3
  • 15
  • 43

1 Answers1

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.

DJClayworth
  • 26,349
  • 9
  • 53
  • 79