求问怎么访问外部变量b,这个代码其他都可以执行,就是没办法访问外部变量b

package com.two;

public class Eight {
    public void show(){
        final int a =1;
        
        int b =2;
        class Ljh{
        int c =3;
        public void print(){
            System.out.println("访问外部a:"+a);
            System.out.println("访问内部c:"+c);
            System.out.println("访问外部b:"+b);
            
        }
        }
        Ljh i = new Ljh();
        i.print();
    }

    public static void main(String[] args) {
        Eight E = new Eight();
        E.show();

    }

}

慕莱坞1282154
浏览 1356回答 1
1回答

李家小凯

用final修饰就好了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java