package com.sf.thread_new; public class TestThread extends Thread{ public TestThread(){} public TestThread(String name){ // 名字是父类提供的属性 // Thread(name) 是父类提供的构造器 super(name); } @Override public void run() { // Thread-0 Thread-1 System.out.println(getName() + " is running"); } public static void main(String[] args) { // main System.out.println(Thread.currentThread().getName() + " is running"); // 创建我们定义的类的线程 TestThread thread1 = new TestThread(); // 直接调用run方法相当于调用函数 不能触发多线程的执行 thread1.start(); TestThread thread2 = new TestThread("thread2"); thread2.start(); } }