public class Example15_1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SpeakHello speakHello;
SpeakNinhao speakNinhao;
speakHello = new SpeakHello();
speakNinhao= new SpeakNinhao();
speakHello.start();
speakNinhao.start();
for(int i=1;i<=5;i++){
System.out.println("大家好"+i+"");
}
}
}
public class SpeakHello extends Thread {
public void run(){
for(int i=1;i<=7;i++){
System.out.println("hello"+i+"");
}
}
}
public class SpeakNinhao {
public void run(){
for(int i=1;i<=7;i++){
System.out.println("ninhao"+i+"");
}
}
}
speakNinhao.start();這個語句Myeclipse裡面報錯:The method start()is undefined for the type 'SpeakNinhao'.我發現即使在SpeakNinhao類裡面寫一個start()也不能通過編譯。誰知道如何改
SpeakNinhao類沒有繼承Thread類