A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

class InnerDemo
{
        public static void main(String[] args)
        {
                Outer.Inner in=new Outer().Inner();
                in.function();
        }
}
class Outer
{

       
        private int x=3;

        class Innter
        {
                int x=4;
                void function()
                {
                        int x=6;
                        System.out.println("inner:"+this.x);
                }
        }

        void method()
        {
                Inner in=new Inner();
                in.function();
        }
       
}
内部类中这个this.x为什么是4,this不是代表对象吗

2 个回复

倒序浏览
加this关键字代表的是当前类里面的对象变量,不是该方法方法里面的变量.就是为了区分有同名的变量名称
回复 使用道具 举报
谢谢亲
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马