众所周知,Thread是继承了Runnable接口并重写run方法实现了线程。那么如果在匿名内部类中如何使用线程,并开启线程呢?
public
class
Test {
public
static
void
main(String[] args) {
//Thread实现的匿名内部类
new
Thread(){
@Override
public
void
run() {
System.out.println(
"aaa"
);
}
}.start();
//Runnable实现匿名内部类
Runnable runnable =
new
Runnable(){
@Override
public
void
run() {
System.out.println(
"bbb"
);
}
};
new
Thread(runnable).start();
}
}