- class Outer
- {
- String s = "1";
- void func_3()
- {
- final String s = "2";
- final String sf = "2";
- class Inner_3
- {
- String s = "3";
- void func_2()
- {
- String s = "4";
- /*这里想访问final类型的那个s = "2",怎么办*/
- System.out.println("Outer.this.s = "+Outer.this.s);
- System.out.println("this.s = "+this.s);
- System.out.println("s = "+s);
- System.out.println("sf = "+sf);
- }
- }
- new Inner_3().func_2();
- }
- }
- class Demo
- {
- public static void main(String[] args)
- {
- new Outer().func_3();
- }
- }
- /*以下是执行结果,每一个引用都有自己所对应的变量,若想访问s = "2"就只能更换变量的名字了
- *Outer.this.s = 1
- *this.s = 3
- *s = 4
- *sf = 2
- */
复制代码 |