答案是C.
好吧,补充一下.
这个setXY方法用了synchronized(线程同步),所以会防止多个线程同时访问这个方法.但是setX()和setY()方法没有synchronized保护,而且setX()和setY()是public公开的,因此C提到的情况会出现.
A.check() can never return true.(错,因为可以不通过setXY()来更改x和y的值)
B.check() can return true when setXY is callled by multiple threads.(错,setXY()是被保护的)
C.check() can return true when multiple threads call setX and setY separately.(正确答案.)
D.check() can only return true if SychTest is changed allow x and y to be set separately.(错.这个其实原则上是对的.但是这个答案用了only一词(只有在这情况下),所以它错了.因为C也是可以造成x!=y.
这道题我搞不懂,
这道题我搞不懂,
20.public class SychTest{
private int x;
private int y;
public void setX(int i){ x=i;}
public void setY(int i){y=i;}
public Synchronized void setXY(int i){
setX(i);
setY(i);
}
public Synchronized boolean check(){
return =y;
}
}
Under which conditions will check() return true when called from a different class?
A.check() can never return true.
B.check() can return true when setXY is callled by multiple threads.
C.check() can return true when multiple threads call setX and setY separately.
D.check() can only return true if SychTest is changed allow x and y to be set separately.
20.public class SychTest{
private int x;
private int y;
public void setX(int i){ x=i;}
public void setY(int i){y=i;}
public Synchronized void setXY(int i){
setX(i);
setY(i);
}
public Synchronized boolean check(){
return =y;
}
}
Under which conditions will check() return true when called from a different class?
A.check() can never return true.
B.check() can return true when setXY is callled by multiple threads.
C.check() can return true when multiple threads call setX and setY separately.
D.check() can only return true if SychTest is changed allow x and y to be set separately.
英语人气:568 ℃时间:2020-06-06 18:44:49
优质解答
我来回答
类似推荐
猜你喜欢
- 1关于数字推理:1 2/3 5/9 () 7/15 4/9 4/9 a1/2 b3/4 c2/13 d3/7
- 2客车与货车分别从甲,乙两地同时相对开出,6小时后在途中相遇,...
- 3我呆在家里一直没出门 用英语怎么说
- 4写出一组食物链,要求由生产者——初级消费者——次级消费者——三级消费者——.——十级消费者!
- 5英语翻译
- 6已知方程2x的平方+6x+a的两根之比为3:2,求a
- 7既属于轴对称图形,又属于中心对称图形的数字,字母,汉字
- 87/2除以2/7-5除以1/2简便计算
- 9计算:cos(π/8)*sin(π/8)=?
- 10把红 黄 蓝三种颜色的小棒各5根混在一起放在盒子里,一次至少拿出多少根?才能保证有3根同色的小棒.