public class ThreadDemo { public static void main(String[] args) { //Thread的匿名实现线程 new Thread(){ public void run(){ System.out.println("!!!"); } }.start(); //Runnable的匿名实现线程, Runnable r = new Runnable(){ public void run(){ System.out.println("###"); } }; new Thread(r).start(); //第三种方法混合了Thread和Runnable new Thread(new Runnable(){ public void run(){ System.out.println("@@@"); } }).start(); } }
这种方法的好处是节省了代码,但是格式不太被人接受