线程的实现方法有两种:
1.是继承Thread类,重写run方法。
2.是实现Runnable接口,实现run方法。
继承Thread:
1 public class Demo8 { 2 3 public static void main(String[] args) { 4 Mytext mytext=new Mytext(); 5 mytext.start(); 6 7 } 8 9 } 10 class Mytext extends Thread { 11 @Override 12 public void run() { 13 System.out.println("继承Thread"); 14 } 15 }
实现Runnable接口:
1 public class Demo9 { 2 3 public static void main(String[] args) { 4 Mytext1 mytext1=new Mytext1(); 5 Thread thread=new Thread(mytext1); 6 thread.start(); 7 8 } 9 10 } 11 class Mytext1 implements Runnable{ 12 13 @Override 14 public void run() { 15 System.out.println("实现Runnable接口"); 16 17 } 18 19 }
原文:https://www.cnblogs.com/luojack/p/10828170.html