public class test {
private final int a;
public test(int a) {
this.a = a;
}
private int getA() {
return a;
}
public void exec() {
new test(1) {
public void print() {
System.out.println(getA());// 0
}
}.print();
}
public static void main(String[] args) {
new test(0).exec();
}
}
public class test {
private final int a;
public test(int a) {
this.a = a;
}
public int getA() {
return a;
}
public void exec() {
new test(1) {
public void print() {
System.out.println(getA());// 1
}
}.print();
}
public static void main(String[] args) {
new test(0).exec();
}
}
差别在于getA()方法的可见性