Java_ multithreaded _ a class inherits from the Thread class and implements the Runnable interface, while creating a thread in two ways, whether the program will be abnormal?

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Chill_Lyn/article/details/102753232

Code of topics

package threadTest;

public class Test extends Thread implements Runnable{
	
	@Override
	public void run() {
		System.out.println("I can run!!");
	}
	
	public static void main(String[] args) {
		//实现Runnable接口创建线程的方式
		Thread t1=new Thread(new Test());
		t1.start();
		//继承Thread类创建线程的方式
		Test t2=new Test();
		t2.start();
	}
}

The result is program works! ! !

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/Chill_Lyn/article/details/102753232