8.5作业1

package day01;

public class MyThread extends Thread{
    public void run() {
        for(int i =0;i<20;i++) {
            Thread t = Thread.currentThread();
            t.setName("Thread-0");
            System.out.println("你好,来自线程"+t.getName());
            
        }
    }

}
package day01;

public class MyThread2 extends Thread{
    public void run() {
        for(int i =0;i<20;i++) {
            
            Thread t = Thread.currentThread();
            t.setName("Thread-1");
            System.out.println("你好,来自线程"+t.getName());
        }
    }

}
package day01;

public class Test {
    public static void main(String[] args) {
        MyThread th =new MyThread();
        MyThread2 th2 =new MyThread2();
        th.start();
        th2.start();
    }

}

原文地址:https://www.cnblogs.com/hxtzzz/p/11302801.html