<pre name="code" class="java">public class hello extends Thread{
private String name;
public hello(){}
public hello(String name){
this.name=name;
}
public void run(){
for(int i=0;i<5;i++){
System.out.println(name+"运行\t"+i);
}
}
public static void main(String args[]){
hello h1=new hello("A");
hello h2=new hello("B");
h1.run();
h2.run();
}
}
Java中线程小示例
最新推荐文章于 2025-10-09 08:00:00 发布
本文介绍了一个简单的Java线程示例程序,该程序创建了两个线程并打印出线程名称及其运行次数。通过继承Thread类的方式实现线程创建,并在run方法中定义线程的行为。
735

被折叠的 条评论
为什么被折叠?



