Java--线程的创建方式(2)

来源:互联网 发布:网络的一颗牙疼的含义 编辑:程序博客网 时间:2024/04/28 05:55
public class MyRun implements Runnable{//可以实现多个接口    private int first;    public MyRun(int first) {        this.first = first;    }    public void run() {        for(int i=first;i<=100;i+=2){            System.out.print(i+" ");        }        System.out.println();    }}
public class MyThread {    public static void main(String[] args) {        Thread t1=new Thread(new MyRun(1));        t1.start();        Thread t2=new Thread(new MyRun(2));        t2.start();        for(int i=101;i<=200;i++){            System.out.print(i+" ");        }        System.out.println();    }}

具体使用那种根据是否与多继承冲突

0 0