`
lx825
  • 浏览: 8568 次
  • 性别: Icon_minigender_2
  • 来自: 郑州
社区版块
存档分类
最新评论

scjp 310-065 No:82 关于synchronized

    博客分类:
  • scjp
阅读更多
QUESTION NO: 82

Which three will compile and run without exception? (Choose three.)

A. private synchronized Object o;
ActualTests.com
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 */ }

Answer: C,E,F

解析:
对于用synchronized 修饰的可以有两种,同步方法和同步代码块,若是同步方法,则直接在方法名前加上synchronized 即可,此时的同步监视器为this;若为同步代码块,则应有一个同步监视器,格式为synchronized (Object o)。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics