?? machine.java
字號:
package correctstart;
public class Machine extends Thread{
private int a=0;
private static int count=0; //統計被啟動的Machine線程的數目
public void start(){
super.start();
System.out.println(currentThread().getName()
+":第"+(++count)+"個Machine線程啟動"); //這行代碼由主線程執行
}
public void run(){
for(a=0;a<50;a++){ //使用Machine對象的實例變量a
System.out.println(currentThread().getName()+":"+a);
try{
sleep(100);
}catch(InterruptedException e){ throw new RuntimeException(e);}
}
}
public static void main(String args[]){
Machine machine1=new Machine();
Machine machine2=new Machine();
machine1.start();
machine2.start();
}
}
/****************************************************
* 作者:孫衛琴 *
* 來源:<<Java面向對象編程>> *
* 技術支持網址:www.javathinker.org *
***************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -