The correct way to start the MyThread thread is:

public class MyThread extends Thread {

    public void run() {...}

}

A. new MyThread().run(); B. new MyThread().start(); C. new MyThread().sleep(); D. None of the above.

Answer: B. new MyThread().start();

Calling start() on a thread object creates a new thread and starts its execution. The run() method is called by the newly created thread. Calling run() directly on the thread object simply executes the run() method in the current thread, which is not the intended behavior for multithreading.

How to Start a Thread in Java: MyThread Example

原文地址: https://www.cveoy.top/t/topic/odUj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录