第一种继承Thread类
package com.tj; public class BasicThread1 extends Thread { public void run() { System.out.println("run方法被调用"); } public static void main(String[] args) { Thread thread = new BasicThread1(); thread.start(); } }
第二种实现Runnable接口
package com.tj; public class BasicThread2 implements Runnable { public void run() { System.out.println("run方法被调用"); } public static void main(String[] args) { Runnable runnable = new BasicThread2(); Thread thread = new Thread(runnable); thread.start(); } }