1. 程式人生 > >Thread類和Runable接口使用

Thread類和Runable接口使用

extends style pan runnable system unable pre string code

不廢話,就一個類,直接拷貝代碼執行

 1 package com.jtfr.demo;
 2 
 3 /**
 4  * 主要:繼承 Thread 類和 Runnable接口
 5  * @author 陳康明 qq:1123181523
 6  * @date 2018年12月27日
 7  */
 8 public class TestBaseDemo {
 9     
10     public static void main(String[] args) {
11         new MyThread().start();
12         new Thread(new
MyRunnable()).start(); 13 } 14 } 15 16 /** 17 * 繼承 Thread 類 18 */ 19 class MyThread extends Thread{ 20 @Override 21 public void run() { 22 System.out.println("繼承的 Thread 類"); 23 } 24 } 25 /** 26 * 實現的 Runnable 接口 27 */ 28 class MyRunnable implements Runnable{
29 30 @Override 31 public void run() { 32 System.out.println("實現的 Runnable 接口"); 33 } 34 35 }

Thread類和Runable接口使用