下列是sleep继承Thread方法
package xheng2;
public class sleep extends Thread {
public void run(){
for (int i = 0; i < 100; i++) {
System.out.println(getName()+":"+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
下列是sleep的测试
package xheng2;
public class cslei {
public static void main(String[] args) {
sleep test1=new sleep();
sleep test2=new sleep();
sleep test3=new sleep();
test1.setName("王烨");
test2.setName("汪艺衡");
test3.setName("摆子");
test1.start();
test2.start();
test3.start();
}
}