fields in interfaces may cause ....ambiguity?


Web tier: servlets, JSP, Web frameworks: fields in interfaces may cause ....ambiguity?

  1. fields in interfaces may cause ....ambiguity? (1 messages)

      In interfaces we will give only declarations for methods.
    In case of fields we must declare them as final.
      If suppose in interface I1 field F is delclared and in I2 also F is declared. And on class C has implemented both I1 and I2, and when I call field F which one is comes .....?

    Maruthi Ram.
  2. Fields on interfaces are both static and final. This means that the field is actually associated with the interface's class object, not the objects implementing the interface.

    interface I1 {
        static final CONSTANT = "C1";

    interface I2 {
        static final CONSTANT = "C2";

    class Example implements I1, I2 {

    Example object = new Example();

    To resolve the ambiguity, use I1.CONSTANT and I2.CONSTANT instead of Example.CONSTANT or object.CONSTANT.