您的位置:首页 > 编程语言 > Java开发

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

2016-05-15 12:36 471 查看
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();
}

}


具体使用那种根据是否与多继承冲突
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: