.java 。 :
1、public ( , 1 )
2、 .java public ( , main 。)
3、 public ,
4、 javac .java , .class
.java , 。
import java.util.Date;
public class ThreadInnerClass {
/**
* @
*/
public static void main(String[] args) {
// :
ThreadInner thread1=new Thread(new ThreadInner());
//thread1.start();// new Thread( Runnable )
// :
// ThreadInner thread2= new Thread(new ThreadInner()," 1")// , 1
//thread2.start();// , new Thread( Runnable ),ThreadInner
// 3:
// new ThreadInner().run();// , main 。
// 4: , runnable , run() .
/*
new Thread(new Runnable(){// runnable
@Override
public void run(){
while(true)
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("1");
}
}
}).start();
*/
// 5:
/*
new Thread(){// run
@Override
public void run(){
System.out.println("2");
}
}.start();
*/
// 6: , Thread,s new
/*
new ThreadInner2(){// Thread, run 。 run
@Override
public void run(){
System.out.println("3");
}
}.start();
*/
}
}
class ThreadInner implements Runnable{
@Override
public void run(){
while(true)
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+" " + new Date());
}
}
}
class ThreadInner2 extends Thread{
}