首页 试题广场 > 试题详情
多选题

【C012037】public class NameList
{
private List names = new ArrayList();
public synchronized void add(String name)
{
names.add(name);
}
public synchronized void printAll() {
for (int i = 0; i < names.size(); i++)
{
System.out.print(names.get(i) + ””);
}
}

public static void main(String[]args)
{
final NameList sl = new NameList();
for (int i = 0; i < 2; i++)
{
new Thread()
{
public void run()
{
sl.add(“A”);
sl.add(“B”);
sl.add(“C”);
sl.printAll();
}
} .start();
}
}
}
Which two statements are true if this class is compiled and run?

  • A.An exception may be thrown at runtime.
  • B.The code may run with no output, without exiting.
  • C.The code may run with no output, exiting normally(正常地).
  • D.The code may rum with output “A B A B C C “, then exit.
  • E.The code may rum with output “A B C A B C A B C “, then exit.
  • F.The code may ruin with output “A A A B C A B C C “, then exit.
  • G.The code may ruin with output “A B C A A B C A B C “, then exit.
提交并查看答案
下一题 上一题
Ke星伙伴们的回答/ 29个回答
关闭
关闭
QQ
交流群
邀请
好友
App
下载
意见
反馈
返回
顶部