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

Innerclasses can access private fields of enclosing instance, but not private me

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • tools
    • None
    • x86
    • windows_95



      Name: mc57594 Date: 02/25/97


      The following code won't compile, because the innerclass accesses a private method.



      import java.lang.*;
      import java.io.*;


      class Outer
      {
          private String s1;

          private void extraOuter() {
              System.out.println("I am the method causing the problem");
          }

          public Outer() {
              s1 = "I am a private instance variable of Outer, I don't cause problems";
          }

          public Runnable giveRunnable() {
              return new Runnable() {
                  public void run() {
                      System.out.println(s1);
                      extraOuter();
                  }
              };
          }
      }


      public class TestInner
      {
          public static void main(String[] args) {
              Outer t = new Outer();
              t.giveRunnable().run();
          }
      }

      company - Hewlett-Packard Labs Bristol , email - ###@###.###
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: