继承类的线程写法

package charpter1;

//类继承父类
public class MyThread01 extends Thread {
// 重写父类方法
@Override
public void run() {
// 让当前线程执行的代码编写在run方法中
for (int i = 0; i <= 100; i++) {
System.out.println("you: " + i);
}
}

}

-------------------------------

package charpter1;

public class TestThread02 {
public static void main(String[] args) {
new Thread(){

@Override
public void run() {
for(int i=0;i<=100;i++){
System.out.println("@@@@@@@@");
}
}

}.start();
System.out.println("main");
new Thread(){

@Override
public void run() {
for(int i=0;i<=100;i++){
System.out.println("******");
}
}

}.start();
}
}

-----------------------------------------------

package charpter1;

public class TestThread01 {
// main是一个线程
public static void main(String[] args) {
// 创建线程对象
MyThread01 thread01 = new MyThread01();
// 调用start方法只是告诉cpu当前线程准备就绪可以执行了,但是什么时候执行由cpu来决定
thread01.start();// 启动线程的正确方式调用start方法
// 创建线程对象
MyThread02 MyThread02 = new MyThread02();
MyThread02.start();
System.out.println("main方法执行结束");

}
}

原文地址:https://www.cnblogs.com/Koma-vv/p/9600212.html