请问在2个方法中,如果没有放入变量,为什么能用this

class Resource
{
private String name;
private int num=1;
boolean flag=false;
public synchronized void setName(String name)
{
if(flag)
{
try
{
this.wait();
}
catch (InterruptedException e)
{
}
}
this.name=name+num;
num++;
System.out.println(Thread.currentThread().getName()+"..生产.."+this.name);

    flag=true;
    this.notify();
}
public synchronized void getName()
{
    if(!flag)
    {
        try
        {
            this.wait();
        }
        catch (InterruptedException e)
        {
        }
    }
    System.out.println(Thread.currentThread().getName()+"..销售.."+this.name);
    flag=false;
    this.notify();
}

}

在上面的代码上,getName方法里为什么能用this.name?

this= object ,类肯定可以访问自己的变量属性啊,你的同步代码块的锁,同样是this

this代表当前对象,当前对象当然可以访问当前对象的成员属性啦

谁来调用这个方法 this就代表谁 this是非静态方法中默认存在的