当前位置: 代码迷 >> J2SE >> Which three will compile and rim without exception?解决方案
  详细解决方案

Which three will compile and rim without exception?解决方案

热度:62   发布时间:2016-04-24 12:53:37.0
Which three will compile and rim without exception?
Which three will compile and rim without exception? (Choose three.)
A. private synchronized Object o;
B. void go() {
synchronized() { /* code here */ }
}
C. public synchronized void go() { /* code here */ }
D. private synchronized(this) void go() { /* code here */ }
E. void go() {
synchronized(Object.class) { /* code here */ }
}
F. void go() {
Object o = new Object();
synchronized(o) { /* code here */ }
}

答案:CEF

其实这题不懂出于对体干英语不认识- -

rim什么意思?跳出?

这题的意思是哪三个会编译成功而且无错误的退出?

请结合答案说明下这题哈~

感激不尽^_^


------解决方案--------------------
就像楼上所说的这道题考察的是JAVA中多线程的同步概念,synchronized 关键字,它包括两种用法:synchronized 方法和 synchronized 块。
A中不能用来生命类的对象
B中的用法不正确 synchronized 方法:通过在方法声明中加入 synchronized关键字来声明 synchronized 方法。
D中估计是想应用 synchronized 块
语法如下:
synchronized(syncObject) {
//允许访问控制的代码
}
解释的可能不是很准确!希望你能明白!!
  相关解决方案