我是Java新手。任何人都可以解釋主要方法中發生了什麼?線程對象創建時設置線程的名字?
class Demo {
public static void main(String []args) {
//setting a name using the constructor
Thread t=new Thread("main"){
//what is this? a static block?? need an explanation to this.
{setName("DemoThread");}
};
//output is DemoThread. Since it set the name again.
System.out.println(t.getName());
}
}