首先给出一个思考题
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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?
|
未完待续