慕哥9229398
2022-06-16 11:11:27
我是一名java初學者,今天下午寫了個程序是這樣的:import java.util.*;public class TestPoint{public static void main(String[] args){MyThread thread= new MyThread();thread.start();try{Thread.sleep(10000);}catch(InterruptedException e){}thread.boot=false;Thread.sleep(10000);thread.in}}class MyThread extends Thread{Boolean boot=true;public void run(){Boolean boot=true;while(boot){System.out.println("==="+new Date()+"===");try{sleep(1000);}catch(InterruptedException e){return;}}}}編譯時cmd顯示找不到符號thread.boot=false;我想是因為我把boot這個變量放在了Mythread類的run方法中的緣故。我把run方法中對布爾值boot的定義語句放到了run方法的外面,編譯就能通過了。所以現在我想問,如果我就是想把boot變量在run方法中定義,我在主函數中不能通過thread.boot這種方式引用該變量,那么,我該通過什么方式引用該變量呢?
2 回答

隔江千里
TA貢獻1906條經驗 獲得超10個贊
你試試將fetchDictionary方法寫到類GraduateResearch1_5里面,在類GraduateResearch1_5中聲明私有變量A、B、C,將在main函數中要做的事放到構造函數中去完成,main函數調用構造函數,形如以下,希望可以幫到你。
public class GraduateResearch1_5{
private int A,B,C,D,E;
public GraduateResearch1_5(){
原來要放到main函數中去做的
}
public static void main(String args[]) {
GraduateResearch1_5 gr = new GraduateResearch1_5();
}
public static void fetchDictionary(String s) {
這里變量A、B、C應該就可以用了
s1[A][B][C] = s.substring(0, i);
......
}
}
添加回答
舉報
0/150
提交
取消