当前位置:SCJP程序员认证考试题库

问题:

[多选]

public class Transfers { 
public static void main(String[] args) throws Exception { 
Record r1 = new Record(); 
Record r2 = new Record(); 
doTransfer(r1, r2, 5); 
doTransfer(r2, r1, 2); 
doTransfer(r1, r2, 1); 
// print the result 
System.out.println(”rl = “ + r1.get() +“, r2=” + r2.get()); 
} 
private static void doTransfer( 
final Record a, final Record b, final int amount) { 
Thread t = new Thread() { 
public void run() { 
new Clerk().transfer(a, b, amount); 
} 
}; 
t.start(); 
} 
} 
class Clerk { 
public synchronized void transfer(Record a, Record b, int amount){ 
synchronized (a) { 
synchronized (b) { 
a.add(-amount); 
b.add(amount); 
} 
} 
} 
} 
class Record { 
int num=10; 
public int get() { return num; } 
public void add(int n) { num = num + n; } 
} 
If Transfers.main() is run, which three are true?()

A .  The output may be “r1 = 6, r2 = 14”.
B .  The output may be “r1 = 5, r2 = 15”.
C .  The output may be “r1 = 8, r2 = 12”.
D .  The code may run (and complete) with no output.
E .  The code may deadlock (without completing) with no output.
F .  M IllegalStateException or InterruptedException may be thrown at runtime.

关于施工成本过程控制中管理行为控制程序的说法,错误的是()。 进行管理行为控制,要考察体系是否处在有效的运行状态。 是为规范项目施工成本的管理行为而制定的约束和激励机制。 管理行为控制是对成本进行过程控制的重点。 目的是确保每个岗位人员在成本管理过程中的管理行为符合事先确定的程序。 投资购买一件艺术品应该必备的要素() 有技术力量。 有一定的资金投入。 此物品有使用价值 ,具有升值预期。 有合作伙伴。 我国古代医学诊断技术“四诊”指望、闻、问和() 查。 验。 测。 切。 比较教育作为一门独立的学科,涉及到政治、经济等多方面的内容,这说明比较教育有() 《萨拉班德》舞曲是在()时期引进法国和美国的。 #61623;A、16世纪早期。 B、16世纪晚期。 C、17世纪早期。 D、17世纪晚期。

public class Transfers { 
public static void main(String[] args) throws Exception { 
Record r1 = new Record(); 
Record r2 = new Record(); 
doTransfer(r1, r2, 5); 
doTransfer(r2, r1, 2); 
doTransfer(r1, r2, 1); 
// print the result 
System.out.println(”rl = “ + r1.get() +“, r2=” + r2.get()); 
} 
private static void doTransfer( 
final Record a, final Record b, final int amount) { 
Thread t = new Thread() { 
public void run() { 
new Clerk().transfer(a, b, amount); 
} 
}; 
t.start(); 
} 
} 
class Clerk { 
public synchronized void transfer(Record a, Record b, int amount){ 
synchronized (a) { 
synchronized (b) { 
a.add(-amount); 
b.add(amount); 
} 
} 
} 
} 
class Record { 
int num=10; 
public int get() { return num; } 
public void add(int n) { num = num + n; } 
} 
If Transfers.main() is run, which three are true?()

参考答案:

  参考解析

本题暂无解析

在线 客服