package algorithm; class Mythread extends Thread{ String name; public Mythread(String name){ this.name=name; } public void run(){ System.out.println(name+":step1"); System.out.println(name+":step2"); System.out.println(name+":step3"); } } class Mythread1 implements Runnable{ String name; Mythread1(String name){ this.name=name; } public void run(){ System.out.println(name+":step1"); System.out.println(name+":step2"); System.out.println(name+":step3"); } } public class Thread1 { public static void main(String[] args) { /* Mythread a = new Mythread("a"); Mythread b = new Mythread("b"); Mythread c = new Mythread("c"); a.start(); b.start(); c.start();*/ Mythread1 a = new Mythread1("a"); Mythread1 b = new Mythread1("b"); Mythread1 c = new Mythread1("c"); Thread t1 = new Thread(a); Thread t2 = new Thread(b); Thread t3 = new Thread(c); t1.start(); t2.start(); t3.start(); } }
时间: 2024-10-12 13:07:21