黑马程序员技术交流社区
标题:
this在内部类时候代表什么,求解
[打印本页]
作者:
插兜
时间:
2015-9-1 17:08
标题:
this在内部类时候代表什么,求解
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不是代表对象吗
作者:
冰蓝水钻
时间:
2015-9-1 17:44
加this关键字代表的是当前类里面的对象变量,不是该方法方法里面的变量.就是为了区分有同名的变量名称
作者:
插兜
时间:
2015-9-1 20:59
谢谢亲
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2