创建线程的方法

package Thread_Example;

class Xc extends Thread    //创建线程 所需要的类 
{
    public void run()
    {
        for(int i=0;i<25;i++)
        {
            System.out.println("子函数");
        }
    }

}
public class Thread_1 {
    public static void main(String[] args){
        Xc xc=new Xc();
        //xc.run();
        xc.start();        //谁调用 的start 方法,程序 就去调用run 方法
                        //start会开启一个线程,而不是 直接调用 
        for(int i=0;i<25;i++)
        {
            System.out.println("主函数");
        }
    }

}

 

posted @ 2019-04-10 17:40  Hunter·Zhang  阅读(78)  评论(0编辑  收藏  举报