public class ExampleThread extends Thread{ @Override public void run() { for(int i = 0; i<100; i++){ System.out.println("i: " + i); } } }
public class Demo { public static void main(String[] args){ ExampleThread t1 = new ExampleThread(); t1.start(); } }
執行 Runnable 介面 :
public class ExampleRunnable implements Runnable{ @Override public void run() { for(int i = 0; i<100; i++){ System.out.println("i: " + i); } } }
public class RunnableDemo { public static void main(String[] args){ ExampleRunnable r1 = new ExampleRunnable(); Thread t1 = new Thread(r1); t1.start(); } }