日期:2014-05-20 浏览次数:20707 次
class 类名 extends Thread{
public void run(){
//方法体
}
}
/**
* 继承Thread类,直接调用run方法
**/
class hello extends Thread{
public hello(){
}
private String name;
public hello(String name){
this.name=name;
}
public void run(){
for(int i=0;i<5;i++){
System.out.println(name+"运行"+i);
}
}
public static void main(String[] args){
hello h1=new hello("A");
hello h2=new hello("B");
h1.run();
h2.run()
}
}
public static void main(String[] args){
hello h1=new hello("A");
hello h2=new hello("B");
h1.start();
h2.start();
}
class 类名 implements Runnable{
public void run(){
//方法体
}
}