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

Declaring a protected method in an interface

    XMLWordPrintable

Details

    • sparc
    • generic

    Description

      I'm doing a stupid little program to try to find a bug in applet loading.
      I needed my Applet subclass A to implement a protocol, so I declared a
      protocol D that just has init() in it.

      The compiler doesn't like having a protected
      method in a protocol. Isn't it a valid thing to do?
      If not, at least the error message should say so.
      Instead, the compiler seems to ignore the "protected"
      (substituting "public") in the interface.

      Here's the error message I get:
      yojimbo% javac A.java
      A.java:6: Methods can't be overridden to be more private. Method void init() is public in interface D.
          protected void init() {
                         ^
      1 error

      -------------- A.java --------------
      import browser.Applet;

      class A extends Applet implements D {
          B myB;

          protected void init() {
      myB = new B();
      System.out.println("B is: " + myB);
          }
      }
      -------------- D.java --------------
      interface D {
          protected void init();
      }

      Attachments

        Issue Links

          Activity

            People

              fyellinsunw Frank Yellin (Inactive)
              kwalrathsunw Kathy Walrath (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: