以下のスニペットをテストしています。tx または t.hello にアクセスする方法を知る必要がありますか? その範囲は何ですか?開発者はこのように変数を定義しますか?
public class Test{
public Test(){
System.out.print("constructor\n");
}
public static void main(String[] args) {
Test t = new Test(){
int x = 0;
//System.out.print("" + x);
void hello(){
System.out.print("inside hello\n");
}
};
}
編集
しかし、なぜこのスニペットが機能したのか
Thread tr = new Thread() {
int loops = 1;
@Override
public void run() {
loops += 1;
}
};
tr.start();