可学答题网 > 问答 > SCJP程序员认证考试题库
目录: 标题| 题干| 答案| 搜索| 相关
问题

Given the following co


Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a, b and c at any time? ()  class Counter {  int v = 0;   synchronized void inc() { v++; }   synchronized void dec() { v--; }   }   public class Q7ed5 {   Counter i;   Counter j;   Counter k;   public synchronized void a() {   i.inc();   System.out.println("a");   i.dec();  }   public synchronized void b() {   i.inc();  j.inc();  k.inc();   System.out.println("b");  i.dec();  j.dec(); k.dec();  }   public void c() {   k.inc();   System.out.println("c");   k.dec();   }   }  

  • Ai.v is guaranteed always to be 0 or 1.
  • Bj.v is guaranteed always to be 0 or 1.
  • Ck.v is guaranteed always to be 0 or 1
  • Dj.v will always be greater than or equal to k.v at any give time.
  • Ek.v will always be greater than or equal to j.v at any give time.
参考答案
参考解析:
分类:SCJP程序员认证考试题库
相关推荐

1、Given the following sc

Given the following scripts, both found in /usr/local/bin, what would the output be when exec...

2、Given the following in

Given the following interface definition, which definitions are valid?()  interface I {  vo...

3、Given the following co

Given the following code fragment:    public void create() {    Vector myVect;&en...

4、Given the following co

Given the following code:   public class Test { void printValue(int m){ do { System.out...

5、Given the following co

Given the following code, which code fragments, when inserted at the indicated location, will&ens...

6、Given the following co

Given the following code:    public class Person{    int arr[] = new int[10];&...