class MyClass1 {
int x = 10;
public static void main(String[] args) {
MyClass1 obj = new MyClass1();
obj.execute();
}
private void execute() {
Thread t = new Thread(new Runnable(){
@Override
public void run() {
System.out.println(this);
System.out.println(MyClass1.this.x);
}
});
t.start();
}
}
Here this refers to an object of anonymous inner class. That is why this.x does not work. But how can we use this to refer to MyClass1 object? Please explain. When we do Sysout(this), it prints out com.java.MyClass1$1@3cd7c2ce where $ specify inner class object. I am not clear on this.