如圖加了一個public就出錯,下面代碼就是;
//守護線程import java.io.*;public class Daemon extends Thread{ private static final int SIZE = 10; private Thread[] t = new Thread[SIZE]; public Daemon(){ setDaemon(true); start(); } public void run(){ for(int i = 0; i < SIZE; i++) t[i] = new DaemonSpawn(i); for(int i = 0; i < SIZE; i++) System.out.println("t[" + i + "].isDaemon() = " + t[i].isDaemon()); while(true) yield(); }}class DaemonSpawn extends Thread{ public DaemonSpawn(int i){ System.out.println("DaemonSpawn "+ i + " started"); start(); } public void run(){ while(true) yield(); }}public class Daemons { public static void main(String[] args){ Thread d = new Daemon(); System.out.println("d.isDaemon() = "+ d.isDaemon()); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Waiting for CR"); try{ stdin.readLine(); } catch(IOException e){ } }}
圖片分辨率太低,看不清。猜測可能是因為你定義了public class,而public class的類名必須和源代碼的文件名保持一致。