问题 单项选择题

关于下列代码编译或执行结果的描述中,正确的是( )。
public class Test
public static void main(String args[])
TestThread pm1=new TestThread("One")
pm1.start();
TestThread pm2=new TestThread("Two")
pm2.start();


class TestTbread extends Thread(
private String sTname="";
TestThread(String s)
sTname=s;

public void run()
for(int i=0;i<2;i++)
try
sleep(1000);
catch(InterruptedException e)
system.out.print(sTname+"");


A.不能通过编译,TestThread类中不能定义变量和构造方法

B.输出One One Two Two

C.输出Two One One Two

D.选项B或C都有可能出现

答案

参考答案:D

解析: 启动两个线程,线程之间没有进行同步,所以B和C均有可能。

单项选择题 A1型题
单项选择题