・2行目でThread実行時に呼び出されるメソッドをオーバーライド
・13,14行目でThreadインスタンスを作成
・16,17行目でThread実行
public class TestThread extends Thread{
public void run() {
for(int i = 0; i < 10; i++) {
System.out.println(getName() + " : " + i);
try {
sleep(1000);
} catch (InterruptedException e) {
}
}
}
public static void main(String[] args){
TestThread thread1 = new TestThread();
TestThread thread2 = new TestThread();
thread1.start();
thread2.start();
}
}