范例1:
class MyThread extends Thread {
private String title;
public MyThread(String title) {
this.title = title;
}
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println(this.title + "->" + i);
}
}
}
public class Demo {
public static void main(String[] args) {
MyThread mt1 = new MyThread("线程1");
MyThread mt2 = new MyThread("线程2");
MyThread mt3 = new MyThread("线程3");
mt1.start();
mt2.start();
mt3.start();
}
}