这是什么原因啊??
class ThreadTest{public static void main(String args[]){
Thread t1=new MyThread("T1");
t1.setPriority(Thread.MIN_PRIORITY);
t1.start();
Thread t2=new MyThread("T2");
t2.setPriority(Thread.MAX_PRIORITY);
t2.start();
Thread t3=new MyThread("T3");
t3.setPriority(Thread.MAX_PRIOIRITY);
t3.start();
}
}
class MyThread extends Thread{
String message;
MyThread(String message){
this.message=message;
static public void run(){
for(int i=0;i<3;i++)
System.out.println(message+" "+getPriority());
}
}
}
ThreadTest.java:18: illegal start of expression
static public void run(){
^
ThreadTest.java:22: ';' expected
}
^
2 errors
----------------解决方案--------------------------------------------------------
run()方法需要抛出异常
正确程序如下:
public class ThreadTest{
public static void main(String args[]){
Thread t1=new MyThread("T1");
t1.setPriority(Thread.MIN_PRIORITY);
t1.start();
Thread t2=new MyThread("T2");
t2.setPriority(Thread.MAX_PRIORITY);
t2.start();
Thread t3=new MyThread("T3");
t3.setPriority(Thread.MAX_PRIORITY);
t3.start();
}//main
}//class ThreadTest
class MyThread extends Thread{
String message;
MyThread(String message)
{
this.message=message;
}//MyThread(message)
public void run()
{
try{
for(int i=0;i<3;i++)
System.out.println(message+" "+getPriority());
}catch(Exception e){}
}//run
}//class MyThread
----------------解决方案--------------------------------------------------------
在run方法里面 并不是每次都要用try 和 catch,用到sleep 还有wait()这些方法的时候要用到try chact的 还有你那个run方法是继承来的不能+static变成静态的
----------------解决方案--------------------------------------------------------
Doctor 好厉害! 问题解决了,结果为: T2 10 T2 10 T2 10 T3 10 T3 10 T3 10 T1 1 T1 1 T1 1
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------
tempnetbar 这个表情什么意思啊?
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------