清阅读下面程序,说明该程序创建线程使用的方法是( )。
publicclassThreadTest
publicstaticvoidmain(Stringargs[])
Threadt1=newThread(newHolloWorld());
Threadt2=newThread(newHolloWorld());
t1.start();
t2.start();
classHolloWorldimplementsRunnable
inti;
publicvoidrun()
while(true)
System.out.println("HolloWorld"+i++);
if(i==5)break;
A.继承Thread类
B.实现Runnable接口
C.t1.start()
D.t2.stan()
参考答案:B
解析: 本题考查线程的创建。在Java中,创建线程有两种方法:①通过实现Runnable接口创建线程。Rurmable接口中只定义了一个rail()方法作为线程体。②通过继承Thread类创建线程,Thread类本身实现了Runnable接口。创建的新的线程不会自动运行,必须调用start()方法才能运行;本题中HolloWorld类实现了Runnable接口。