package com. 1the1ma
pub1ic class MyRunnable implements Runnable {
@Override
public void run() {
for(int i=0; i<100; i++) {
System . out . print1n( Thread. currentThread() .getName()" :"+i);
}
}
public class MyRunnableDemo {
public. static void main(String[] args) {
//创建MyRunnable类的对象
MyRunnable my = new MyRunnable();
//创建Thread类的对象,把MyRunnable对 象作为构造方法的参数
//Thread (Runnable target )
//Thread tI = new Thread(my);
//Thread t2 = new Thread(my);
//Thread (Runnable target, String name)
Thread t1 = new Thread(my, name: “高铁");
Thread t2 = new Thread(my, name: "飞机");| I
//启动线程
t1.start();
t2.start();
}
}