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

Default access field inherited across package boundaries.

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

      A method extends a superclass in another package and a superinterface.
      The superclass and the superinterface both define a field with the
      same name. The instance in the superclass has default access so it
      is not inherited by the (main) subclass. Yet, the two field
      declarations create an ambiguity that javac cannot handle.

      Discovered with Modena test c0814703.

      algol% cat ambig2.java
      import Spack.S;

      interface I {
      int i=1;
      }
      // public class S {
      // int i=-1;
      // int getI(){ return i; }
      // void setI( int j ){ i=j; }
      // }
      public class Ambig2 extends S{
      public static void main( String[] argv ) {
      Ambig2 a = new Ambig2();
      System.out.println(a.i);
      }
      }
      algol% cat S.java

      package Spack;

      public class S {
      int i=-1;
      int getI(){ return i; }
      void setI( int j ){ i=j; }
      }
      algol% setenv CLASSPATH .
      algol% java -fullversion
      java full version "1.1.4n:1997.09.11"
      algol% javac -d . S.java
      algol% javac -d . Ambig2.java
      Ambig2.java:15: Variable i in class Ambig2 not accessible from class Ambig2.
                      System.out.println(a.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: