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 - ###@###.###
======================================================================
- duplicates
-
JDK-4051281 Problem compiling when inner class references a private method
-
- Closed
-
- relates to
-
JDK-4046432 Compiler failed to lookup nested class in InnerClass
-
- Closed
-