多选题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(”

题目
多选题
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.


相似考题
更多“多选题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(””相关问题
  • 第1题:

    有以下程序:includeusing namespace std;class R{public:R(int r1,int r2){R1=r1;R2=

    有以下程序: #include<iostream> using namespace std; class R { public: R(int r1,int r2) { R1=r1; R2=r2; } void print(); void print0const; private: int R1,R2; }; void R::print() { cout<<R1<<","<<R2<<endl; } void R::print() const { cout<<Rl<<","<<R2<<endl; } int main() { R a(5,4); const R b(20,52); b.print(); return 0; } 执行后的输出结果是( )。

    A.5,4

    B.20,52

    C.0,0

    D.4,5


    正确答案:B

  • 第2题:

    有以下程序:include using namespace std;class R{public: R(int f1,int r2) {R1=r1;

    有以下程序: #include <iostream> using namespace std; class R { public: R(int f1,int r2) { R1=r1; R2=r2; } void print(); void print ()const; private: int R1, R2; }; void R: :print() { cout<<R1<<", "<<R2<<end1; } void R: :print() const { cout<<Rl<<", "<<R2<<end1; } int main () { R a(5,4); const R b(20,52); b.print (); return 0; } 执行后的输出结果是

    A.5,4

    B.20,52

    C.0,0

    D.4,5


    正确答案:B
    解析:使用const关键词修饰的对象成为常对象,题中对象b被声明为类R的常对象。使用const关键词说明的成员函数称为常成员函数,类R中用const重载了函数print()。在使用常对象和常成员函数时应注意以下几点:①const是函数类型的一个组成部分,因此在函数部分也要带const关键词。②常成员函数不能更新对象的数据成员,也不能调用该类中没有用const修饰的成员函数。③如果将一个对象说明为常对象,则通过该常对象只能调用它的常成员函数,不能调用其他的成员函数。④const关键词可以参与区分重载函数。本题中,b为类R的常对象,通过b只能调用类R的常成员函数print()输出20,52。

  • 第3题:

    有以下程序 include using namespace std; class R{ public: R(int r1,int r2){R1=r

    有以下程序

    #include <iostream>

    using namespace std;

    class R

    {

    public:

    R(int r1,int r2)

    {

    R1=r1;

    R2=r2;

    }

    void print();

    void print()const;

    private:

    iht R1,R2;

    };

    A.5,4

    B.20,52

    C.0,0

    D.4,5


    正确答案:B
    解析:使用const关键字修饰的对象成为常对象,题中对象b被声明为类R的常对象。使用const关键字说明的成员函数称为常成员函数,类R中用const重载了函数print()。在使用常对象和常成员函数时应注意的是:const是函数类型的一个组成部分,因此在常成员函数部分也要带const关键字:常成员函数不能更新对象的数据成员,也不能调用该类中没有用const修饰的成员函数:如果将一个对象说明为常对象,则通过该常对象只能调用它的常成员函数,不能调用其他的成员函数;const关键字可以参与区分重载函数。本题中,b为类R的常对象,通过b只能调用类R的常成员函数print()输出20,52。

  • 第4题:

    有阻值分别为R1和R2的两个负载,其中R1的电阻值是R2的N倍,把它们并联后接到电源上,则:(”x^m”表示“x的m次方”)()

    • A、R1两端的电压与R2的相同,R1消耗的功率是R2的1/N
    • B、R1两端的电压与R2的相同,R1消耗的功率是R2的N^2倍
    • C、R1两端的电压是R2的1/N,R1消耗的功率是R2的1/N^2
    • D、R1两端的电压是R2的N倍,R1消耗的功率是R2的N^2倍

    正确答案:A

  • 第5题:

    Routers R1 and R2 are EIGRP neighbors. R1 has been configured with the eigrp stub connected command. Which of the following is true as a result?()

    • A、R1 can learn EIGRP routes from R2, but R2 cannot learn EIGRP routes from R1
    • B、R1 can send IP packets to R2, but R2 cannot send IP packets to R1
    • C、R2 no longer learns EIGRP routes from R1 for routes not connected to R1
    • D、R1 no longer replies to R2's Query messages
    • E、R2n o longer sends to R1 Query messages

    正确答案:C,E

  • 第6题:

    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.

    正确答案:A,B,E

  • 第7题:

    极性最大的是()

    • A、R1=β-D-洋地黄毒糖-β-D葡萄糖,R2=甲基
    • B、R1=氢,R2=醛基
    • C、R1=α-L鼠李糖,R2=醛基
    • D、R1=α-L鼠李糖-β-D葡萄糖,R2=甲基
    • E、R1=氢,R2=甲基

    正确答案:D

  • 第8题:

    public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finally
    • B、 exception finished
    • C、 finally exception finished
    • D、 Compilation fails.

    正确答案:C

  • 第9题:

    public class Starter extends Thread {  private int x= 2;  public static void main(String[] args) throws Exception {  new Starter().makeItSo();  }  public Starter() {  x=5;  start();  }  public void makeItSo() throws Exception {  join();  x=x- 1;  System.out.println(x);  }  public void run() { x *= 2; }  }  What is the output if the main() method is rum?() 

    • A、 4
    • B、 5
    • C、 8
    • D、 9
    • E、 Compilation fails.
    • F、 An exception is thrown at runtime.
    • G、 It is impossible to determine for certain.

    正确答案:D

  • 第10题:

    两个电阻R1和R2做串联连接,当R1和R2具有以下数值时,试求串联的等效电阻: ①R1=R2=1Ω;②R1=3Ω,R2=6Ω。


    正确答案: ①R=R1+R2=1+1=2(Ω)
    ②R=R1+R2=3+6=9(Ω)
    ①的串联的等效电阻是2Ω;②的串联等效电阻为9Ω。

  • 第11题:

    多选题
    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.


    正确答案: D,E
    解析: 暂无解析

  • 第12题:

    多选题
    public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i<4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()
    A

    0, 2, 4, 4, 6, 8, 10, 6,

    B

    0, 2, 4, 6, 8, 10, 2, 4,

    C

    0, 2, 4, 6, 8, 10, 12, 14,

    D

    0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,

    E

    0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,


    正确答案: A,E
    解析: 暂无解析

  • 第13题:

    有以下程序;include using namespace std;class R{public:R(int r1,int r2){R1=r1;R2

    有以下程序; #include <iostream> using namespace std; class R { public: R(int r1,int r2) { R1=r1; R2=r2; } void print(); void print () const; private: int R1, R2; }; void R::print () { cout<<R1<<","<<R2<<endl; } void R::print() const { cout<<R1<<", "<<R2<<endl; } int main () { R a(5,4); const R b(20,52); b.print(); return 0; } 执行后的输出结果是

    A.5,4

    B.20,52

    C.0,0

    D.4,5


    正确答案:B
    解析:使用const关键字修饰的对象成为常对象,题中对象b被声明为类R的常,对象。使用const关键字说明的成员函数称为常成员函数,类R中用const重载了函数print()。在使用常对象和常成员函数时应注意的是:const是函数类型的一个组成部分,因此在常成员函数部分也要带const关键字;常成员函数不能更新对象的数据成员,也不能调用该类中没有用const修饰的成员函数;如果将一个对象说明为常对象,则通过该常对象只能调用它的常成员函数,不能调用其他的成员函数;const关键字可以参与区分重载函数。本题中,b为类R的常对象,通过b只能调用类R的常成员函数print()输出20,52。

  • 第14题:

    听力原文:[解析] 有以下程序:includeusing namespace Std;Class R{public:R(int r1,i

    听力原文:[解析]

    有以下程序: #include<iostream> using namespace Std; Class R {public: R(int r1,int r2) {R1=r1; R2=r2;} void print(); void print()const; private: int R1,R2;}; roid R::print() {cout<<R1<<“,”<<R2<<endl;} void R::print()con

    A.5,4

    B.20,52

    C.0,0

    D.4,5


    正确答案:B
    解析: 使用const关键字修饰的对象成为常对象,题中对象b被声明为类R的常对象。使用const关键宇说明的成员函数称为常成员函数,类R中用const重载了函数print()。在使用常对象和常成员函数时应注意的是:const是函数类型的一个组成部分,因此在常成员函数部分也要带const关键宇;常成员函数不能更新对象的数据成员,也不能调用该类中没有用const修饰的成员函数;如果将一个对象说明为常对象,则通过该常对象只能调用它的常成员函数,不能调用其他的成员函数;const关键字可以参与区分重载函数。

  • 第15题:

    有阻值分别为R1和R2的两个负载,其中R1的电阻值是R2的N倍,把它们并联后接到电源上,则:(”x^m”表示“x的m次方”)()

    • A、流过R1的电流是R2的N倍,R1消耗的功率是R2的N^2倍
    • B、流过R1的电流是R2的1/N,R1消耗的功率是R2的1/N
    • C、流过R1的电流与R2的相同,R1消耗的功率是R2的1/N^2
    • D、流过R1的电流与R2的相同,R1消耗的功率是R2的N倍

    正确答案:B

  • 第16题:

    计算题:两个电阻R1和R2并联连接,当R1和R2具有下列数值时,试求并联的等效电阻。①R1=R2=2Ω;②R1=2Ω,R2=0。


    正确答案: ①R=R1×R2/(R1+R2)=2×2/(2+2)=2(Ω)
    ②R=R1×R2/(R1+R2)=2×0/(2+0)=0(Ω)

  • 第17题:

    Two directly connected routers, R1 and R2, are both configured for OSPF graceful restart. R2 is able to switch packets in hardware, but R1 is not. If a network administrator logs on to R2 and performs a system reload, which will be the result?()

    • A、Traffic forwarded from R2 to or through R1 will continue to be forwarded based on the forwarding table state at the time of the reload.
    • B、R2 will continue to forward traffic to R1, but R1 will drop the traffic because its neighbor adjacency with R2 has failed.
    • C、R2 will continue forwarding traffic to and through R1, but R1 will drop this traffic because it is not capable of maintaining its forwarding state.
    • D、All the traffic R2 is forwarding to or through R1 will be dropped while OSPF rebuilds its neighbor adjacency and forwarding tables.

    正确答案:A

  • 第18题:

    class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the result?() 

    • A、 TestA
    • B、 TestB
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第19题:

    以下ARM指令中不属于数据处理类指令的是()

    • A、ADC R1,R2,R3
    • B、LDR R1,[R2]
    • C、MOV R1,R2,LSL#4
    • D、ORR R1,R2,R3

    正确答案:B

  • 第20题:

    public class Threads 1 {  intx=0;  public class Runner implements Runnable {  public void run() {  int current = 0;  for(int=i=0;i<4;i++){  current = x;  System.out.print(current + “, “);  x = current + 2;  }  }  }  public static void main(String[] args) {  new Threads1().go();  }  public void go() {  Runnable r1 = new Runner();  new Thread(r1).start();  new Thread(r1 ).start();  }  }  Which two are possible results?()

    • A、 0, 2, 4, 4, 6, 8, 10, 6,
    • B、 0, 2, 4, 6, 8, 10, 2, 4,
    • C、 0, 2, 4, 6, 8, 10, 12, 14,
    • D、 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
    • E、 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

    正确答案:A,C

  • 第21题:

    电阻R1,R2并联,已知R1>>R2,并联后的等值电阻近似等于R1,即R≈R1


    正确答案:错误

  • 第22题:

    单选题
    以下不能完成将R2中数值的两倍写入R1中的ARM指令是()
    A

    ADD R1,R2,R2

    B

    ORR R1,R2,R2

    C

    MOV R1,R2,LSL#1

    D

    MUL R1,R2,#2


    正确答案: A
    解析: 将R2寄存器中的数值的两倍写入R1,可以通过加法指令、移位指令(逻辑左移相当于乘操作)和乘法指令完成,故选项中仅B项无法完成,本题选B。

  • 第23题:

    单选题
    Two directly connected routers, R1 and R2, are both configured for OSPF graceful restart. R2 is able to switch packets in hardware, but R1 is not. If a network administrator logs on to R2 and performs a system reload, which will be the result?()
    A

    Traffic forwarded from R2 to or through R1 will continue to be forwarded based on the forwarding table state at the time of the reload.

    B

    R2 will continue to forward traffic to R1, but R1 will drop the traffic because its neighbor adjacency with R2 has failed.

    C

    R2 will continue forwarding traffic to and through R1, but R1 will drop this traffic because it is not capable of maintaining its forwarding state.

    D

    All the traffic R2 is forwarding to or through R1 will be dropped while OSPF rebuilds its neighbor adjacency and forwarding tables.


    正确答案: A
    解析: 暂无解析

  • 第24题:

    单选题
    public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()
    A

     finally

    B

     exception finished

    C

     finally exception finished

    D

     Compilation fails.


    正确答案: C
    解析: 暂无解析