本帖最后由 ⑷嚸V恱 于 2013-8-13 18:14 编辑
下面是毕老师讲的代码片段:
class Bank {
private int sum;
public syschronized void add(int n){
sum=sum+n;
try{
Thread.sleep(10);
catch(Exception e){
}
System.out.println("sum="+sum);
}
}
}
class Bank {
private int sum;
public void add(int n){
syschronized ()
sum=sum+n;
try{
Thread.sleep(10);
catch(Exception e){
}
System.out.println("sum="+sum);
}
}
} |
|