线程、静态、构造函数
时间:2010-11-01 来源:铨铨灰
public class Thread1 implements Runnable { public Thread1() { System.out.println("constructor"); } public static void s(){ System.out.println("static function"); } static {//静态代码块; System.out.println("static ..."); } public void run() { System.out.println(Thread.currentThread().getName()+":run"); } public static void main(String []args){ Thread1.s();//静态方法可以通过//类名.方法//来调用 Thread1 t1 = new Thread1(); Thread t = new Thread(t1); t.run();//主函数main调用方法run() t.start();//线程t开始 } } /* * 输出结果为: * static * constructor * main:run * Thread-0:run */
相关阅读 更多 +
排行榜 更多 +