单选题void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?()AThis code may throw an InterruptedException.BThis code may throw an IllegalStateException.CThis code may thr

题目
单选题
void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?()
A

 This code may throw an InterruptedException.

B

 This code may throw an IllegalStateException.

C

 This code may throw a TimeoutException after ten minutes.

D

 This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.

E

 Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.

F

 A call to notify() or notifyAll() from another thread may cause this method to complete normally.


相似考题

3. 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.

更多“单选题void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?()A  This code may throw an InterruptedException.B  This code may throw an IllegalStateException.C  This code m”相关问题
  • 第1题:

    void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?() 

    • A、 This code may throw an InterruptedException.
    • B、 This code may throw an IllegalStateException.
    • C、 This code may throw a TimeoutException after ten minutes.
    • D、 This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.
    • E、 Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.
    • F、 A call to notify() or notifyAll() from another thread may cause this method to complete normally.

    正确答案:B

  • 第2题:

    Given the following code fragment:     public void create() {     Vector myVect;     myVect = new Vector();      }  Which of the following statements are true?() 

    • A、 The declaration on line 2 does not allocate memory space for the variable myVect.
    • B、 The declaration on line 2 allocates memory space for a reference to a Vector object.
    • C、 The statement on line 2 creates an object of class Vector.
    • D、 The statement on line 3 creates an object of class Vector.
    • E、 The statement on line 3 allocates memory space for an object of class Vector.

    正确答案:A,D,E

  • 第3题:

    Which the two are true about the JSTL core iteration custom tags?()

    • A、 It may iterate over arrays, collections, maps and strings.
    • B、 The body of the tag may contain EL code, but not scripting code.
    • C、 When looping over collections, a loop status object may be used in the tag body.
    • D、 It may iterate over a map, but only the key of the mapping may be used in the tag body.
    • E、 When looping over integers (for example begin1=’1’ end=’10’), a loop status object may not be used in the tag body.

    正确答案:A,C

  • 第4题:

    Consider the following class:     class Test(int i) {     void test(int i) {  System.out.println(“I am an int.”); }    void test(String s) {   System.out.println(“I am a string.”);     }          public static void main(String args) {    Test t=new Test();     char ch=“y”;    t.test(ch);     }      }     Which of the statements below is true?()

    • A、 Line 5 will not compile, because void methods cannot be overridden.
    • B、 Line 12 will not compile, because there is no version of test() that rakes a charargument.
    • C、 The code will compile but will throw an exception at line 12.
    • D、 The code will compile and produce the following output: I am an int.
    • E、 The code will compile and produce the following output: I am a String.

    正确答案:D

  • 第5题:

    In your Certkiller .com database server the parameter PLSQL_CODE_TYPE has been set to NATIVE. Which object would be achieved by the setting?()

    • A、The source PL/SQL code will be stored in native machine code.
    • B、The source PL/SQL code will be stored in interpreted byte code.
    • C、The compiled PL/SQL code will be stored in native machine code.
    • D、The compiled PL/SQL code will be stored in interpreted byte code.

    正确答案:C

  • 第6题:

    You work as an application developer at Certkiller .com. Certkiller .com has instructed you to create a class named MetricFormula. This class will be used to compare MetricUnit and EnglishUnit objects.The MetricFormula is currently defined as follows (Line numbers are used for reference purposes only): 1. public class MetricFormula2. { 3. 4. } You need to ensure that the MetricFormula class can be used to compare the required objects. What should you do? ()

    • A、 Add the following code on line 1: : IComparable {
    • B、 Add the following code on line 1: : IComparer {
    • C、 Add the following code on line 3: public int Compare (object x, object y) {// implementation code }
    • D、 Add the following code on line 3: public int CompareTo (object obj) {// implementation code }

    正确答案:B,C

  • 第7题:

    多选题
    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
    解析: 暂无解析

  • 第8题:

    单选题
    Click the Exhibit button.   What is the result?()
    A

     The code will deadlock.

    B

     The code may run with output "2 0 6 4".

    C

     The code may run with no output.

    D

     The code may run with output "0 6".

    E

     An exception is thrown at runtime.

    F

     The code may run with output "0 2 4 6".


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

  • 第9题:

    多选题
    public class Team extends java.util.LinkedList {  public void addPlayer(Player p) {  add(p);  }  public void compete(Team opponent) { /* more code here */ }  }  class Player { /* more code here */ }  Which two are true?()
    A

    This code will compile.

    B

    This code demonstrates proper design of an is-a relationship.

    C

    This code demonstrates proper design of a has-a relationship.

    D

    A Java programmer using the Team class could remove Player objects from a Team object.


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

  • 第10题:

    单选题
    class Computation extends Thread {  private int num;  private boolean isComplete;  private int result;  public Computation(int num) { this.num = num; }  public synchronized void run() {  result = num * 2;  isComplete = true;  notify();  }  public synchronized int getResult() {  while (!isComplete) {  try {  wait();  } catch (InterruptedException e) { }  }  return result;  }  public static void main(String[] args) {  Computation[] computations = new Computation [4];  for (int i = 0; i < computations.length; i++) {  computations[i] = new Computation(i);  computations[i] .start();  }  for (Computation c : computations)  System.out.print(c.getResult() +“ “);  }  }  What is the result?()
    A

     The code will deadlock.

    B

     The code may run with no output.

    C

     An exception is thrown at runtime.

    D

     The code may run with output “0 6”.

    E

     The code may run with output “2 0 6 4‟.

    F

     The code may ruin with output “0 2 4 6”.


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

  • 第11题:

    单选题
    In your Certkiller .com database server the parameter PLSQL_CODE_TYPE has been set to NATIVE. Which object would be achieved by the setting?()
    A

    The source PL/SQL code will be stored in native machine code.

    B

    The source PL/SQL code will be stored in interpreted byte code.

    C

    The compiled PL/SQL code will be stored in native machine code.

    D

    The compiled PL/SQL code will be stored in interpreted byte code.


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

  • 第12题:

    单选题
    Which the statement is true?()
    A

     The Error class is a Runtime Exception.

    B

     No exceptions are subclasses of Error.

    C

     Any statement that may throw an Error must be enclosed in a try block.

    D

     any statement that may throw an Exception must be enclosed in a try block.

    E

     Any statement that may throw an Runtime Exception must be enclosed in a try block.


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

  • 第13题:

    public class Team extends java.util.LinkedList {  public void addPlayer(Player p) {  add(p);  }  public void compete(Team opponent) { /* more code here */ }  }  class Player { /* more code here */ }  Which two are true?()

    • A、 This code will compile.
    • B、 This code demonstrates proper design of an is-a relationship.
    • C、 This code demonstrates proper design of a has-a relationship.
    • D、 A Java programmer using the Team class could remove Player objects from a Team object.

    正确答案:A,D

  • 第14题:

    import java.util.*;  public class NameList {  private List names = new ArrayList();  public synchronized void add(String name) { names.add(name); }  public synchronized void printAll() {  for (int i = 0; i System.out.print(names.get(i) +“ “); }  }  public static void main(String[] args) {  final NameList sl = new NameList();  for(int i=0;i<2;i++) {  new Thread() {  public void ruin() {  sl.add(”A”);  sl.add(”B”);  sl.add(”C”);  sl.printAll();  }  }.start();  }  }  }  Which two statements are true if this class is compiled and run?()

    • A、 An exception may be thrown at runtime.
    • B、 The code may run with no output, without exiting.
    • C、The code may rum with output “A B A B C C “, then exit.
    • D、The code may ruin with output “A A A B C A B C C “, then exit.
    • E、 The code may rum with output “A B C A B C A B C “, then exit.
    • F、The code may ruin with output “A B C A A B C A B C “, then exit.

    正确答案:E,F

  • 第15题:

    Which three will compile and run without exception?()

    • 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 */}

    正确答案:C,E,F

  • 第16题:

    class Computation extends Thread {  private int num;  private boolean isComplete;  private int result;  public Computation(int num) { this.num = num; }  public synchronized void run() {  result = num * 2;  isComplete = true;  notify();  }  public synchronized int getResult() {  while (!isComplete) {  try {  wait();  } catch (InterruptedException e) { }  }  return result;  }  public static void main(String[] args) {  Computation[] computations = new Computation [4];  for (int i = 0; i < computations.length; i++) {  computations[i] = new Computation(i);  computations[i] .start();  }  for (Computation c : computations)  System.out.print(c.getResult() +“ “);  }  }  What is the result?() 

    • A、 The code will deadlock.
    • B、 The code may run with no output.
    • C、 An exception is thrown at runtime.
    • D、 The code may run with output “0 6”.
    • E、 The code may run with output “2 0 6 4‟.
    • F、 The code may ruin with output “0 2 4 6”.

    正确答案:F

  • 第17题:

    You create a Web page named TestPage.aspx and a user control named TestUserControl.ascx. TestPage.aspx uses TestUserControl.ascx as shown in the following line of code. On TestUserControl.ascx, you need to add a read-only member named CityName to return the value "New York". You also must add code to TestPage.aspx to read this value. Which two actions should you perform?()

    • A、Add the following line of code to the TestUserControl.ascx.cs code-behind file. public string CityName { get { return "New York"; } } 
    • B、Add the following line of code to the TestUserControl.ascx.cs code-behind file. protected readonly string CityName = "New York"; 
    • C、Add the following code segment to the TestPage.aspx.cs code-behind file. protected void Page_Load(object sender, EventArgs e) { string s = testControl.CityName; } 
    • D、Add the following code segment to the TestPage.aspx.cs code-behind file. protected void Page_Load(object sender, EventArgs e) { string s = testControl.Attributes["CityName"]; } 

    正确答案:A,C

  • 第18题:

    You are implementing an ASP.NET Web site. The site uses a component that must be dynamically configured before it can be used within site pages. You create a static method named SiteHelper.Configure that configures the component. You need to add a code segment to the Global.asax file that invokes the SiteHelper.Configure method the first time, and only the first time, that any page in the site is requested. Which code segment should you use? ()

    • A、void Application_Start(object sender, EventArgs e) { SiteHelper.Configure(); }
    • B、void Application_Init(object sender, EventArgs e) { SiteHelper.Configure(); }
    • C、void Application_BeginRequest(object sender, EventArgs e) { SiteHelper.Configure(); }
    • D、Object lockObject = new Object(); void Application_BeginRequest(object sender, EventArgs e) { lock(lockObject()) { SiteHelper.Configure(); } }

    正确答案:A

  • 第19题:

    多选题
    import java.util.*;  public class NameList {  private List names = new ArrayList();  public synchronized void add(String name) { names.add(name); }  public synchronized void printAll() {  for (int i = 0; i System.out.print(names.get(i) +“ “); }  }  public static void main(String[] args) {  final NameList sl = new NameList();  for(int i=0;i
    A

    An exception may be thrown at runtime.

    B

    The code may run with no output, without exiting.

    C

    The code may rum with output “A B A B C C “, then exit.

    D

    The code may ruin with output “A A A B C A B C C “, then exit.

    E

    The code may rum with output “A B C A B C A B C “, then exit.

    F

    The code may ruin with output “A B C A A B C A B C “, then exit.


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

  • 第20题:

    多选题
    Which three will compile and run without exception?()
    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 */ }


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

  • 第21题:

    多选题
    Given the following code fragment:     public void create() {     Vector myVect;     myVect = new Vector();      }  Which of the following statements are true?()
    A

    The declaration on line 2 does not allocate memory space for the variable myVect.

    B

    The declaration on line 2 allocates memory space for a reference to a Vector object.

    C

    The statement on line 2 creates an object of class Vector.

    D

    The statement on line 3 creates an object of class Vector.

    E

    The statement on line 3 allocates memory space for an object of class Vector.


    正确答案: C,D
    解析: SL-275中指出:要为一个新对象分配空间必须执行new Xxx()调用,new调用执行以下的操作: 
    1.为新对象分配空间并将其成员初始化为0或者null。 
    2.执行类体中的初始化。(例如在类中有一个成员声明int a=10;在第一步后a=0 ,执行到第二步后a=10)    
    3.执行构造函数。 
    4.变量被分配为一个到内存堆中的新对象的引用。

  • 第22题:

    单选题
    In your Supportcenter.cn database server the parameter PLSQL_CODE_TYPE has been set to NATIVE. Which object would be achieved by the setting?()
    A

    The source PL/SQL code will be stored in native machine code.

    B

    The source PL/SQL code will be stored in interpreted byte code.

    C

    The compiled PL/SQL code will be stored in native machine code.

    D

    The compiled PL/SQL code will be stored in interpreted byte code.


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

  • 第23题:

    单选题
    Consider the following class:     class Test(int i) {     void test(int i) {  System.out.println(“I am an int.”); }    void test(String s) {   System.out.println(“I am a string.”);     }          public static void main(String args) {    Test t=new Test();     char ch=“y”;    t.test(ch);     }      }     Which of the statements below is true?()
    A

     Line 5 will not compile, because void methods cannot be overridden.

    B

     Line 12 will not compile, because there is no version of test() that rakes a charargument.

    C

     The code will compile but will throw an exception at line 12.

    D

     The code will compile and produce the following output: I am an int.

    E

     The code will compile and produce the following output: I am a String.


    正确答案: D
    解析: 在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。