Rule No. 1 in Java: if you have more than one class in your application, you only can use "public" key word in the class which has main method (public static void main( ) ...). Try the following code and name your file as Test2.java (not Test.java):
class Test implements Runnable { // remove public key word here
public void run() {
for (int i=1; i<=10; i++){
System.out.println("Test:"+i);
}
}
}
public class Test2 { // add public keyword here if you want to
public static void main (String args[]){
Test te = new Test();
Thread t = new Thread(te);
t.start();
}
}
Compile Test2.java and run it:
C:\>java Test2
Cheer.
- A java question. Miao, Franco CAWS:EX
- Re: A java question. Nic Jackson
- Re: A java question. Chen Chao
- Re: A java question. Robert Burdick
- Re: A java question. Ronald Wildenberg
- OOT:Web Logic JavaSoft
- Re: OOT:Web Logic rOcK cACinG
- Re: A java question. Duffey, Kevin
- Re: A java question. Gare, Trefor
- Re: A java question. Mattias Jiderhamn
- Re: A java question. Joe Cheng
- Re: A java question. Gare, Trefor
