问题
单项选择题
阅读下面程序
public cmass ThreadTest
public static void main(String args[])
Thread t1=new Thread(new Hello());
Thread t2=new Thread(new Hello());
t1.start();
t2.start();
class Hello implements Runnable
int i;
public void run()
while(true)
System.out.println("Hello"+i++);
it(i==5) break;
此程序创建线程所使用的方法是
A.继承Thread类
B.实现Runnable接口
C.t1.start()
D.t2.start()
答案
参考答案:B
解析: 实现Runnable接口和继承Thread类是创建线程的两种方式。本题程序显然通过实现Runnable接口创建了线程。