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

protected methods permitted in interfaces

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0fcs
    • CPU:
      sparc
    • OS:
      generic, solaris_2.5
    • Verification:
      Not verified

      Description

      This compiles but should not. The 'protected' appears to be ignored.


      interface SomeInterface
      {
        protected void method();
      }

      The description field as copied from bug report 1214648 follows:

      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

              • Assignee:
                fyellinsunw Frank Yellin (Inactive)
                Reporter:
                jjg Jonathan Gibbons
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: