万能百科  > 计算机   > 

[填空题] 通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序 【9】 。 public class ThreadTest pu

2021-07-20   

[填空题] 通过实现Runnable接口创建线程,请在画线处加入正确的代码完成此程序 【9】

public class ThreadTest

public static void main(String args[ ])

Thread t1=new Thread(new Hello());

Thread t2=new Thread(new Hello());

______;

t2.start();

class Hello implements Runnable

int i;

public void run()

while(true)

System.out.println("Hello"+i++);

if(i==5) break;

正确答案:

t1.start();

参考解析:

题中Hello类实现了Runnable接口,在ThreadTest类的main()方法中,Hello类的两个实例对象分别创建了t1、t2两个线程,并将线程启动。那么程序体中的画线处应该是将t1线程启动(调用方法start())。

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

标签