java——无法使用内部类的属性

2019年2月16日15:35:05 发表评论 918 views
/**
 * Created by xabcd on 2019/2/16.
 */
public class java_outer
{
    int score = 95;
    void inst()
    {
        Inner in = new Inner();
        in.display();
    }
    class Inner
    {
        //添加内部类属性
        String name = "张三";
        void display()
        {
            System.out.println("成绩:score="+score);
        }
    }
    public void print()
    {
        //在此调用内部类的name属性
        System.out.println("姓名"+name);
    }
}




/**
 * Created by xabcd on 2019/2/16.
 */
public class test_outer
{
    public static void main(String[] args)
    {
        java_outer ou = new java_outer();
        ou.inst();
    }
}



结果 java报错,提示无法找到name


发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: