Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4094618

Private field in superclass collides with public field in superinterface.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.4, 1.2.0
    • tools
    • generic
    • generic


      allan.jacobs@Eng 1997-10-13

      The class Ambig extends S and implements I. Both S and I define a field i, but
      this field is private in S. Therefore, Ambig inherits i from I only. There
      should not be any ambiguity. Problem discovered using Modena test c0814702.

      algol% cat Ambig.java
      interface I {
              int i=1;
      }
      class S {
              private int i=-1;
              int getI(){ return i; }
              void setI( int j ){ i=j; }
      }
      public class Ambig extends S implements I {
              public static void main( String[] argv ) {
      Ambig a = new Ambig();
                      System.out.println(a.i);
              }
      }
      algol% java -fullversion
      java full version "1.1.4n:1997.09.11"
      algol% setenv CLASSPATH .
      algol% javac -d . Ambig.java
      Ambig.java:13: Reference to i is ambiguous. It is defined in interface I and class S.
                      System.out.println(i);
                                         ^
      1 error

            tturnidgsunw Todd Turnidge (Inactive)
            ajacobssunw Allan Jacobs (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: