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

Inherited method from package private class throws IllegalAccessError

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • tools
    • sparc
    • solaris_2.6



      Name: bk70084 Date: 06/26/98


      Prior to jdk1.2beta3 the following code produced:

      java pkg2.TestExtendedClass
      Testing Extended Class

      using jdk1.2beta3:

      java pkg2.TestExtendedClass
      java.lang.IllegalAccessError: try to access class pkg1/PackagePrivateClass from class pkg2/TestExtendedClass
              at pkg2.TestExtendedClass.<init>(TestExtendedClass.java:12)
              at pkg2.TestExtendedClass.main(TestExtendedClass.java:22)

      In your test directory, place the three files at these locations:
      pkg1/PackagePrivateClass.java
      pkg1/ExtendedClass.java
      pkg2/TestExtendedClass.java

      Compile and run with the test directory on your classpath, and you get the above Exception.


      --------------------------------------------------
      the code:
      --------------------------------------------------

      //
      // PackagePrivateClass.java
      //
      package pkg1;

      /**
       * A package-private class
       */
      class PackagePrivateClass
      {
        private String str;

        public PackagePrivateClass(String str)
        {
          this.str = str;
        }

        public void printStr()
        {
          System.out.println(str);
        }
      }

      //
      //ExtendedClass.java
      //
      package pkg1;

      /**
       * Public class that extends a package-private class
       */
      public class ExtendedClass extends PackagePrivateClass
      {
        public ExtendedClass(String str)
        {
          super(str);
        }
      }

      //
      //TestExtendedClass.java
      //
      package pkg2;

      import pkg1.*;

      public class TestExtendedClass
      {
        private ExtendedClass ec;

        public TestExtendedClass(String str)
        {
         // Instantiate a new ExtendedClass object
         ec = new ExtendedClass(str);

         // Call the method printStr() that Extended Class
         // inherits from the PackagePrivateClass
         ec.printStr();
        }

        public static void main(String[] args)
        {
          TestExtendedClass test =
            new TestExtendedClass("Testing Extended Class");
        }
      }
      (Review ID: 34362)
      ======================================================================

            tturnidgsunw Todd Turnidge (Inactive)
            bklocksunw Brian Klock (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: