Create a thread inherits the Thread class way

1  // inherited Thread class 
2  public  class the MyThread the extends Thread {
 . 3      // override method run 
. 4      public  void run () {
 . 5          for ( int I = 0; I <20 is; I ++ ) {
 . 6              System.out.println ( " Hello, from the thread "+ Thread.currentThread () getName ());.
 . 7          }
 . 8      }
 . 9 }
Thread class inheritance
1 //测试类
2 public class Test {
3     public static void main(String[] args) {
4         MyThread mythread = new MyThread();
5         MyThread mythread1 = new MyThread();
6         mythread.start();//启动线程
7         mythread1.start();
8     }
9 }
测试类

运行结果:

 

Guess you like

Origin www.cnblogs.com/Dean-0/p/11305065.html