面向对象——内部类(2)

来源:互联网 发布:浩方对战平台mac版 编辑:程序博客网 时间:2024/06/14 22:31
/*内部类定义在局部时,1,不可以被成员修饰符修饰2,可以直接访问外部类中的成员,因为还持有外部类中的引用。但是不可以访问它所在的局部中的变量。只能访问被final修饰的局部变量。*/class Outer{int x = 3;void method(final int a){final int y = 4;class Inner{void function(){System.out.println(y);}}new Inner().function();}}class  InnerClassDemo3{public static void main(String[] args) {Outer out = new Outer();out.method(7);out.method(8);}}