读书人

内部类方式的继承类

发布时间: 2012-11-03 10:57:43 作者: rapoo

内部类形式的继承类

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()方法的可见性

读书人网 >编程

热点推荐