範例
public
static
class
ICThread
extends
Thread {
public
void
run() {
System.out.println( System.currentTimeMillis() );
}
}
public
static
void
main(
String
[] args ) {
(
new
ICThread()).start();
}
解決方案
實作
Runnable
,而不延伸
Thread
。
public
static
class
ICRunnable
implements
Runnable {
public
void
run() {
System.out.println( System.currentTimeMillis() );
}
}
public
static
void
main(
String
[] args ) {
(
new
Thread(
new
ICRunnable() )).start();
}