62,614
社区成员
发帖
与我相关
我的任务
分享
class MyWork extends Thread{
@Override
public void run() {
for(int i=0;i<5;++i){
System.out.println(this.getName()+": "+i);
}
}
}
public class Test {
public static void main(String[] args) throws InterruptedException{
Thread t=new Thread(new MyWork(),"A");
t.start();
}
}
运行结果:
Thread-0: 0
Thread-0: 1
Thread-0: 2
Thread-0: 3
Thread-0: 4
class MyWork extends Thread{
public MyWork(String name){
super(name);
}
@Override
public void run() {
for(int i=0;i<5;++i){
System.out.println(this.getName()+": "+i);
}
}
}
public class Test {
public static void main(String[] args) throws InterruptedException{
Thread t=new MyWork("AAA6");
t.start();
}
}
运行结果:
AAA6: 0
AAA6: 1
AAA6: 2
AAA6: 3
AAA6: 4
class Thread{
private Runnable runnable;
@Override
public void run() {
runnable.run();
}
}