您的位置:首页 > 其它

创建线程的方法一:继承Thread类

2009-11-02 18:51 316 查看
class Lefthand extends Thread {
public void run() {
for(int i=0;i<=5;i++) {
System.out.println("You are Students!");
try{
sleep(500);
}catch(InterruptedException e){}
}
}
}
class Righthand extends Thread {
public void run() {
for(int i=0;i<=5;i++) {
System.out.println("I am a Teacher!");
}try{
sleep(300);
}catch(InterruptedException e) {}
}
}
public class ThreadTest {
static Lefthand left;
static Righthand right;
public static void main(String args[]) {
left=new Lefthand();
right=new Righthand();
left.start();
right.start();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐