继承Thread类实现多线程

class MyThreadextends Thread{

         private String title;

         public MyThread(String title){

                   super();

                   this.title = title;

         }

         @Override

         public void run(){

                   for(int i =1;i <= 50;i++)

                   {

                            System.out.println(title+"------"+i);

                   }

         }

}

 

public classTestDemo{

         public static void main(String[] args){

                   MyThread mt1 = newMyThread("线程A");

                   MyThread mt2 = newMyThread("线程B");

                   MyThread mt3 = newMyThread("线程C");

                  

                   mt1.start();

                   mt2.start();

                   mt3.start();

         }

}

结论:要想启动线程必须依靠Thread类实现start()方法执行,线程启动之后会默认调用run()方法