#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+" "); }
}
}