// The "Tester" class.
import java.applet.*;
import java.awt.*;
public class Tester
{
public static void main (String[] args)
{
ThreadTest ex1 = new ThreadTest();
ThreadTest2 ex2 = new ThreadTest2();
ex1.start();
ex2.start();
}
} //Tester class
public class ThreadTest extends Thread
{
public ThreadTest()
{
}
public void run()
{
while (true)
{
System.out.println ("Hello");
delay (1000);
}
}
public void delay (int num)
{
Thread.currentThread().setPriority (Thread.MIN_PRIORITY);
try
{
Thread.sleep (num);
}
catch (InterruptedException ex)
{
ex.printStackTrace();
}
Thread.currentThread().setPriority (Thread.MAX_PRIORITY);
}
} // ThreadTest class
public class ThreadTest2 extends Thread //This is where the error is
{
public ThreadTest2()
{
}
public void run()
{
while (true)
{
System.out.println ("Hello2");
delay (1000);
}
}
public void delay (int num)
{
Thread.currentThread().setPriority (Thread.MIN_PRIORITY);
try
{
Thread.sleep (num);
}
catch (InterruptedException ex)
{
ex.printStackTrace();
}`enter code here
Thread.currentThread().setPriority (Thread.MAX_PRIORITY);
}
} // ThreadTest2 class
我不明白每次嘗試運行代碼時彈出的錯誤。彈出的誤差是在java中聲明2個類是public有什麼錯誤?
「的類型‘ThreadTest2’被聲明在compliation單元公共‘G:/Java/newstuff/Tester.java’中也包含了公共類型,‘測試’,」
安置自己的錯誤,請 –
我這樣做,我收到了錯誤寫入底部。 – Jade
這個也是[爲什麼只有一個公共類](http://stackoverflow.com/questions/3578490/why-only-1-public-class-in-java-file) –