#Java多線程小案例
##子線程一
package thread;
public class SpeakCar extends Thread{
public void run() {
for(int i=1;i<=20;i++) {
System.out.print(“轎車”+i+" ");
}
}
}
##子線程二
package thread;
public class SpeakElephant extends Thread{
public void run() {
for(int i=1;i<=20;i++) {
System.out.print(“大象”+i+" ");
}
}
}
##程序運行2個線程
package thread;
import java.util.Calendar;
import java.util.Date;
public class thread {
public static void main(String[] args) {
SpeakElephant speakElephant;
SpeakCar speakCar;
speakElephant=new SpeakElephant();
speakCar=new SpeakCar();
speakElephant.start();
speakCar.start();
Date nowTime=new Date();
System.out.println(nowTime);
Calendar c2=Calendar.getInstance();
System.out.println(c2);
for(int i=1;i<15;i++) {
System.out.print("主人"+i+" "); }
}
}